in reply to match whitespace or beginning/end of string
Some solutions:
/(?:\A|\s)(beta="second")(?:\s|\Z)/
/(?<!\S)(beta="second")(?!\S)/
" $_ " =~ /\s(beta="second")\s/
However, I don't see why the following doesn't suffice:
/\b(beta="second")/
You're obviously not writing a validator, and the double quote mark is unambiguously the end of what you want to match. The \b at the start is necessary to avoid accidentally matching alphabeta="fourth", but there's no need for anything similar at the end since the double quote can't be part of anything else.
Update: I just noticed
a general-purpose rule which works even without the quotes.
Again, no problem
/\b$id=(?:"[^"]*"|\w+)/
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: match whitespace or beginning/end of string
by azadian (Sexton) on Nov 02, 2009 at 15:02 UTC | |
by ikegami (Patriarch) on Nov 02, 2009 at 15:36 UTC |