tempAccount wrote:What we're trying to do is extract all property/value pairs out of something like this, and the img tag, by using only one regex statement.
<a property1="value1" property2="value2"><img src="imgURL"/></a>
I boiled it down to the 6 letter string to not get distracted with countless other methods of extracting this.
But by doing so, you leave so many details out, so that it's impossible to give a proper answer (all IMHO, of course!).
tempAccount wrote:The essence of the question is if regex can do this kind of thing in one statement.
Still, here are some example strings, and the values i'd like to extract. Maybe they make more sense now:
Y => Y
aAY => (a, A) and Y
aBZ => (a, B) and Z
bCX => (b, C) and X
aAbAX => (a, A) (b, A) and X
aAaAaAY => (a, A) (a, A) (a, A) and Y
bAcAaAZ => (b, A) (c, A) (a, A) and Z
No, such small examples tell nothing about the real problem (as I can see from your next example). Sorry.
tempAccount wrote:so in the real world example:
<a property1="value1" property2="value2"><img src="imgURL"/></a>
find:
(property1, value1) (property2, value2) and imgURL
Well, there's something to work with!
Perhaps you could explain this in a bit more detail? Looking at this one example, one might think that you want to match all key-value pairs except when the key is "src", in which case you only want to match the value (and not the key), which this regex will take care of:
Code: Select all
'/\b((?:(?!src|\s).)*)="([^"]++)"/i' // not properly tested, but should do what I described above
It could also mean to match all key-value pair except for the last pair: in that case only match the value, which could be accomplished by this one:
Code: Select all
'/([^\s=]++(?=.*?[^\s=]++="[^"]++"))?="([^"]++)"/i'
But it might mean something entirely different. That's why I asked for a couple of example's: then I might deduce these rules from the examples myself. Of course, it would be better if you could explain it yourself in detail: it's the first step in solving your problem: being able to properly explain it to someone who has no prior knowledge of your problem.
HTH.