Forum Moderators: coopster

Message Too Old, No Replies

regex (capturing a repeated subpattern)

capturing subpatterns that are repeated

         

thing3b

5:47 am on Mar 11, 2004 (gmt 0)

10+ Year Member



Sorry if this has been asked before, I could not find simalar posts.

I am using a PCRE regex function to get parts of a string.
my current pattern is:
$pattern = "/<([^\s]+)\s+([^\s]+)\s+([^\s]+)\s*><\/a>/i";
and my string is:
$string = '<a href="123" href="456" ></a>';
This will match.

The problem is that ([^\s]+)\s+ in the pattern is repeated.
in the string it is:
([^\s]+)\s+([^\s]+)\s+
How can I change my pattern so that ([^\s]+)\s+ does not need to be repeated like this.

As I am capturing the output, I can not use (([^\s]+)\s+)+ as it will only capture the last string match, not all of them.

Thanks,
Bud Smith

coopster

9:59 pm on Mar 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



It seems like you want to load an array with any attribute settings in the
a
element. Or are you trying to accomplish something specific, such as locating duplicate href attribute settings in that particular element?

The reason I ask is you may be better off using something like:

$array = explode(' ', $string);
Just a thought.