in reply to Regex question - negatives
Can someone suggest to me what I'm doing wrong?
The .+ looks wrong, since it can match [[ and ]] too. You should use [^\]]+ in the first place.
Update: Here's a working regex:
\[\[([^\]]+)]]
But it stops at a single ]. To prevent that, you need a negative look-ahead:
\[\[((?:(?!\]\]).)+)]]
Now that's quite unreadable, so here in detail:
\[\[ # opening delimiter ( # capture... (?: # a group (?!\]\]) # that does not start with ]] . # and is a single character long )+ # and many of these groups, at least one. ) ]] # closing delimiter
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex question - negatives
by JavaFan (Canon) on Jan 13, 2011 at 10:52 UTC | |
|
Re^2: Regex question - negatives
by ultranerds (Hermit) on Jan 13, 2011 at 09:49 UTC | |
|
Re^2: Regex question - negatives
by ultranerds (Hermit) on Jan 13, 2011 at 10:24 UTC | |
by ELISHEVA (Prior) on Jan 13, 2011 at 10:43 UTC | |
by ultranerds (Hermit) on Jan 13, 2011 at 10:51 UTC | |
by jwkrahn (Abbot) on Jan 13, 2011 at 11:10 UTC | |
by ELISHEVA (Prior) on Jan 13, 2011 at 11:00 UTC | |
by ultranerds (Hermit) on Jan 13, 2011 at 11:03 UTC |