Jump to content

Sildhe

Members
  • Posts

    5
  • Joined

  • Last visited

    Never

Everything posted by Sildhe

  1. oh okay I get what you're saying. If id=.. isn't there, then it's gonna keep on gobbling stuff up. That makes sense. So how would I write it? Seems like opposite of what I'm trying to do with the FLAG, so would I us positive lookahead?
  2. Inside the anchor tag I have <a.*?id=([0-9.]+)[^>]*?> I suppose I don't need that last ? in there but I did use [^>]* to match till the end of the anchor tag. I have .*? after <a because there are any number of things between the start of the anchor tag and where it lists id=1234.5 I thought a non-greedy match all would be the best thing for that. Am I wrong?
  3. hmm...you guys' ideas seem to work by itself, but it's actually part of a larger regex. Probably another part of my regex is causing this stuff to mess up, or something, I don't know. I ended up just doing a capture on everything between the anchor tags with no condition, and then using a foreach loop and strpos to further filter out the ids, based on the captured stuff between the anchor tags. That seems to work fine. Thanks for the help guys, appreciate it.
  4. Okay basically I'm looking for an expanded version of a negative character class. For instance, say I have this string: $string = " <a href='blah' id=1234.2>[FLAG] something</a> <a href='blah' id=829.1>somethingelse</a> <a href='blah' id=634.5>somerandomcharlength</a> "; I want to capture the id but only if '[FLAG] ' between the anchor tag is not there. '[FLAG] ' will always be immediately after the closing '>' of the opening anchor tag and it will always have a space right after it. If it is not there, the stuff between the anchor tags will start immediately after the '>' for the opening tag (no space). So for this example, I want to capture 829.1 and 634.5 but not 1234.2 I think the answer is negative lookbehind, so here's what I've tried: preg_match_all("/<a.*?id=([0-9.]+)[^>]*?>(?<!\[FLAG\] ).*?<\/a>/",$string,$matches); I've also tried wrapping the .*? in non-capturing parenthesis like so: preg_match_all("/<a.*?id=([0-9.]+)[^>]*?>(?<!\[FLAG\] )(?:.*?)<\/a>/",$string,$matches); But it continues to match all 3 ids. So...what am I doing wrong?
×
×
  • 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.