regex - comparing two string by adding pattern in perl -
I want to match two strings and then want to add some tags to the final output. For example
$ String1 = "adaptive actuator failure and structural & lt; match & gt; loss & lt; / match & gt; Nasa's compensation"; $ String 2 = "adaptive actuator failure & lt ;? $ 262 #? & Gt; and to show structural damage ?, show $ 262 #? & Gt; NASA compensation;
Output Requirement:
"Adaptive Actuator Failure & lt ;? $ 262 Show? And Structural & lt; Mail & gt; Damage & lt; / Match & gt; & Lt ;? Shows $ 262? & Gt; NASA Compensation
Explanation: I want to map data from string 1 to string 2 but the problem is with string 2, which has additional element, this element can come anywhere in string 2 .
Note: We can not remove the tag from string 2 because we want to put it in the final output
I tried to add an element pattern to each letter but it does not work Used to be.
I have tried the code:
$ every = "(?: (?: \\ s * & lt; [\\ # \\ s \\ \ $ \\ w \\ = \\ - \\\; $ each "(" \\ / \\] & gt \\ *) + s)? ": (?: \\ s * are < \\ # \\ s \\ $ \\ w \\ = \\ - \\\ "\\ / \\?] & Gt; \\ s *) + '"; Post text "itemprop =" text "> You can use regexps in this way, be careful, it will not be very strong, it is working only for sensible inputs.
Use Strict; Use of Alerts Do my $ string 1 = "adaptive actuator failure and structural & lt; Match & gt; Damage & lt; / Match & gt; NASA's compensation "; My $ string 2 =" Adaptive actuator failure & lt ;? Shows $ 262? & Gt; And structural damage & lt ;, show $ 262 #? & Gt; NASA compensation; #search string1 my $ se1 = $ string1; My $ se2 = $ string2; #remove all tags $ se1 = ~ s! & Lt; [^ & Gt;] * & gt; !! Gis; $ Se2 = ~ s! & Lt; [^ & Gt;] * & gt; !! Gis; #nac $ se1 = ~ s! \ S +! ! GIS; $ Se2 = ~ s! \ S +! ! GIS; # Get a match if ($ se1 eq $ se2) {# to tag my s1 my $ s = $ string1; While ($ s = ~ s! (^ [^ & Gt;] * & gt;) (. +?) (& Lt; / \ s * [^ & gt;] * & gt;) !! ) {My $ begin_tag = $ 1; My $ end_tag = $ 3; My $ text = $ 2; ### With Tag $ string2 = ~ s replace text in s2! $ Text! $ Begin_tag $ text $ end_tag! is; }}
Comments
Post a Comment