PDA

View Full Version : pattern match


vhan
02-19-2004, 11:12 PM
I have an expression if $index =~ 3|7|11|15|19, and I only want to match those numbers. Only, the number "13" is being returned because the number 3 is part of the bunch to match. How do I tell it to only match on the first digit so that 13 isn't returned?

dswimboy
02-20-2004, 02:26 AM
depends on what the string is.

/\b3\b/ will match only " 3 " or "3" or "3 " or " 3". \b is the word-boundary anchor.

/^3/ will match 3 at the beginning of the string, and anything after it.

/^3$/ will match only 3, with no spaces

hope this helps. if not, describe your problem more.