SPUG: ifs and whiles and hashes...
dougb at scalar.org
Wed Aug 18 19:59:16 CDT 1999
On Wed, Aug 18, 1999 at 04:51:05PM -0700, Tim Maher/CONSULTIX wrote:
> According to Doug Beaver:
> > You almost never want to use .* or .*? in order to match stuff like that
> > anyways, you want to use this:
> > "([^"]*)"
> - or ([^"]+), depending on the minimal acceptable match.
> Good idea Doug, but according to his code, he was trying to match up
> to the next \" sequence, not the next ". He may have mistakenly
> been trying to (unnecessarily) escape the " characters, in which
> case your approach above would be appropriate, but I recommended
> the .*? approach on the basis of his apparent need to match up to
> the next \" sequence.
(The \" vs " thing has already been discussed...)
I still advocate using a negated character class instead of .*? in
almost all situations, .*? has pitfalls that are hard to understand
until you've been bitten by them a few times. ;-) See pp 226-227 of
Mastering Regular Expressions for details.
(I'd list the pitfalls and show some example input and matches using
both .*? and a negated character class, but I'm leaving town soon and
have too much work to finish before I leave... :-/)
Smithers: I'm afraid we have a bad image, Sir. Market research shows
people see you as somewhat of an ogre.
Burns: I ought to club them and eat their bones!
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
POST TO: spug-list at pm.org PROBLEMS: owner-spug-list at pm.org
Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/
SUBSCRIBE/UNSUBSCRIBE: Replace ACTION below by subscribe or unsubscribe
Email to majordomo at pm.org: ACTION spug-list your_address
More information about the spug-list