lbr@holos0.uucp (Len Reed) (02/27/91)
The manual speaks of, but does not define, a "word boundary" in regular expressions. I presume that a word is \w+ and that a word boundary will match at ^ and $ and at the edges of, but not within, \w+ . I'm trying to match 6 digit strings, but I don't want to match a six digit string that is part of a larger alphanumeric string. The following seems to work. Is it in fact what I want? /\b\d{6}\b/ -- Len Reed Holos Software, Inc. Voice: (404) 496-1358 UUCP: ...!gatech!holos0!lbr
lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/27/91)
In article <1991Feb26.183337.24976@holos0.uucp> lbr@holos0.uucp (Len Reed) writes:
: The manual speaks of, but does not define, a "word boundary" in
: regular expressions. I presume that a word is \w+ and that a word
: boundary will match at ^ and $ and at the edges of, but not
: within, \w+ .
That's more or less correct. \b matches between \w and \W (in either order),
where the beginning and end of the string are considered to be bounded by \W.
: I'm trying to match 6 digit strings, but I don't want to match a
: six digit string that is part of a larger alphanumeric string.
: The following seems to work. Is it in fact what I want?
: /\b\d{6}\b/
Yes.
Larry
rbj@uunet.UU.NET (Root Boy Jim) (02/28/91)
In <1991Feb26.183337.24976@holos0.uucp> lbr@holos0.uucp (Len Reed) writes: >The manual speaks of, but does not define, a "word boundary" I'm glad you asked! It provides me with a soapbox for my next speech. Perhaps perl needs a Syntax Table? After all, while we've run out of special variables and are into control variables, we've got all those special arrays (of both types) just dying to be used. While it couldn't modify perl syntax, it might be applicable to pattern matching characters on user data. For example, many lanuages allow $ as characters in variable names. I mention this out of completeness. I have yet to use syntax tables, even in emacs, altho I would probably notice their absence (creaky major modes) if they weren't there. What does everyone think? -- [rbj@uunet 1] stty sane unknown mode: sane