Jump to content

Repeated bit of text - Possibly quite simple...


Grego

Recommended Posts

Essentially, I want to look for the same bit of text twice in the string. So if I had the string "<tag>Hello</tag>", it would be recognised. However, if the string were "<tag>Hello</notag>" I want it to not be recognised. Currently I'm using my extremely basic regex of:

"<(.*?)>(.*?)<\/(.*?)>" but this is mixing the tags up and causing problems. How can I change it so that the first and third references (in bold) have to be the same?

 

Thanks in advance =D

Really need to see some sample data, but study/take a look at these patterns for matching duplicate xml nodes in xml data:

~(?m)^(.*+)$(?=(?:\r?\n.*+)*?\r?\n\1$)~

<a href="http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=4xm5cyfp">Seen here.</a>

 

~^(.*)$(?=.*\1)~ms

<a href="http://nancywalshee03.freehostia.com/regextester/regex_tester.php?seeSaved=ddjcgh5m">Seen here.</a>

I hope this is what you mean by sample data...

 

Will Match:

<tag>Text</tag>

<tagt>Text</tagt>

 

Won't Match:

<tag>Text</tagt>

<tagt>Text</tag>

 

So I need it to look for a closing tag which is the same as the opening tag and match those together, returning the tag name (tag/tagt) and the string in between the tags (Text)...

 

Is that what you wanted to know? If it helps, I was using <notag> as just a name. In retrospect that wasn't a very smart idea...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.