Your skill will accomplish what the force of many cannot |
|
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
Why has everybody else kept the \b? I can't answer for others, but for me, throwing in boundary assertions like this is a reflexive, defensive (and possibly cargo-cultish) move I tend to use when I'm dealing with "words". The string the Anonymous Monk gives as an example is fairly straightforward: it's delimited by whitespace and the beginning and end of the string. As you say, \b will not help here (update: No! See tybalt89's reply), though it does no harm. Unfortunately, "words" be tricky. Is "word's" one word or two? If it's supposed to be one word, then Anonymous Monk's /\b\w*\d\w*\b/ or /\w*\d\w*/ or, I think, any of the other solutions I've seen so far will fail to match it with or without \bs. Words like "t'other", "wouldn't've", "words'" or "left-handed" can be difficult to deal with. I'm sure one could give many other examples, and that's just in English! In general, I think (?<! \S) and (?! \S) would serve better than \b as word boundaries (update: in the OPed case). But once again, it is unfortunately true that there are few generalities in human language. Give a man a fish: <%-{-{-{-< In reply to Re^3: regex search for words with one digit (updated)
by AnomalousMonk
|
|