Bob, et al -- ...and then Bob Showalter said... % % > -----Original Message----- % > From: David T-G [mailto:[EMAIL PROTECTED]] ... % > Whoops! No it won't -- .* is greedy! % > % > You need something more like ... % > /(p1)[^(p2)]*(p2)/g ; ... % This does not match on input data like: % % (p1)foo2baz(p2) % (p1)foo(bar)baz(p2) % % See the flaw?
Because the [^] will happily match ( and ), right? Yeah, I wondered about that. I didn't know whether David was looking for the literal string "(p1)", looking for "p1" and (saving) it as $1, or just pointing out the very generic 'p1' in his code. In the first case, we'd have to escape the parens -- in all cases, including the /search/. In the second case, we can skip the parens in the [^"don't match this"] block. In the third case, it doesn't really matter 'cuz we don't need them anywhere. Hey, at least I said "something more like", even though I didn't know just how that something should look ;-) I'm quite happy to have learned that .*? is non-greedy; that seems much more elegant than excluding "(p2)" or "p2" or whatever (imagine if p2 were a long string; ugh). Meanwhile, though, is there any way to not-match a more-than-one-char string? Suppose I wanted to search various email addresses and not match lauratg maditg quintg and I wanted to do it simply. I'd love to be able to say /foo@here|[^(laura|madi|quin)tg]@mysite|bar@there/ to simplify the regexp as well as not have to turn it inside out like ! /lauratg|maditg|quintg/ or so. Thanks & TIA & HAND :-D -- David T-G * It's easier to fight for one's principles (play) [EMAIL PROTECTED] * than to live up to them. -- fortune cookie (work) [EMAIL PROTECTED] http://www.justpickone.org/davidtg/ Shpx gur Pbzzhavpngvbaf Qrprapl Npg!
msg28072/pgp00000.pgp
Description: PGP signature