in reply to Regex question
If you use a regex, you're going to have to quotemeta one of the strings because '.' is a meta (regex command) character.
If you use substr, you'll have problems if the length of the part you are trying to match can vary. Ie. Could the strings be '13.2.3' & '13.2' for example.
Using index will allow you to avoid both these problems. You simple want to know if the shorter string matches the longer string at position 0:
$var1 = '1.1.2'; $var2 = '1.1'; if( index( $var1, $var2 ) == 0 ) { print "matches" } else { print "Doesn't match" }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regex question
by Skeeve (Parson) on May 22, 2007 at 12:44 UTC | |
by BrowserUk (Patriarch) on May 22, 2007 at 13:42 UTC | |
by Skeeve (Parson) on May 22, 2007 at 22:47 UTC |