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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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...

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.