Page 1 of 1

Removing redundant entries in RegExp

Posted: Tue Mar 22, 2005 1:25 am
by anjanesh
Again another RegExp q:
I managed to do a pattern /..../is that will be give me the results. But there are some which are repeated - because they exist in the string to search for.
What do I have to do to get unique ones.
For example, a string may contain a lot of links in the form
<a id="12345" href="something">link</a>

Code: Select all

<a id=&quote;12345&quote; href=&quote;something&quote;>link</a>
<a id=&quote;54321&quote; href=&quote;something&quote;>link</a>
<a id=&quote;99999&quote; href=&quote;something&quote;>link</a>
<a id=&quote;12345&quote; href=&quote;something&quote;>link</a>
<a id=&quote;85858&quote; href=&quote;something&quote;>link</a>
My pattern matches 5 - there are 2 that are same. How do I remove redundant entries ? The result should be 4 matches.
Im using preg_match_all.
Thanks

Posted: Tue Mar 22, 2005 1:48 am
by n00b Saibot
try array_unique on matches array.

Posted: Tue Mar 22, 2005 1:54 am
by anjanesh
Thats after preg_match_all has been executed - any way to have it done while searching in RegExp ?

Posted: Tue Mar 22, 2005 3:46 am
by Chris Corbyn
The RegExp wont do that unfortunately.... I'd go with n00b Saibot's option :D