Finding lines with different words between tags

Find, replace, find in files, replace in files, regular expressions

Finding lines with different words between tags

Postby greg123 » Sun Oct 02, 2011 5:31 am

Hi,

In a large txt file I'm unsuccessfully trying to find lines, that contain different words between tags <tag1></tag1> and <tag2></tag2>.

Example:

<tag1>abc</tag1><tag2>abc</tag2>
<tag1>def</tag1><tag2>def</tag2>
<tag1>xxx</tag1><tag2>ccc</tag2>

In this example only <tag1>xxx</tag1><tag2>ccc</tag2> line should be matched. Please help.

Best regards,
Greg
greg123
Newbie
 
Posts: 7
Joined: Mon Jun 21, 2010 5:48 am

Re: Finding lines with different words between tags

Postby Mofi » Sun Oct 02, 2011 7:19 am

What about searching with Perl regular expression engine for <tag1>(.*)</tag1><tag2>\1</tag2> with using button Hide Lines. That hides all lines containing the same string between both tags and the remaining lines are those with different strings between the two tags.
User avatar
Mofi
Grand Master
Grand Master
 
Posts: 3936
Joined: Thu Jul 29, 2004 11:00 pm
Location: Vienna

Re: Finding lines with different words between tags

Postby greg123 » Sun Oct 02, 2011 10:21 am

I can't believe it's so simple.
Thanks a lot!!!
greg123
Newbie
 
Posts: 7
Joined: Mon Jun 21, 2010 5:48 am

Re: Finding lines with different words between tags

Postby pietzcker » Sun Oct 09, 2011 3:35 pm

Another way would be to search for

Code: Select all
<tag1>(.*?)</tag1><tag2>(?!\1).*</tag2>

This matches pairs of tag1/tag2 tags that don't have the same content.
User avatar
pietzcker
Master
Master
 
Posts: 242
Joined: Sun Aug 22, 2004 11:00 pm


Return to Find/Replace/Regular Expressions