reg exact string matching

S

sivga

Hi

how do i match a string exactly for eg

$stringid is pid-3-1

i need to match pid-[0-9*]-[0-9*] and not anything like pid-3-1-1 or
pid-3 ,pid-3-1-1-1 etc

allowed possibilities are

pid-any no of digits-any no of digits

this is the code i have but does not seem to work

if ($stringid eq 'pid-[0-9*]-[0-9*]' ) {
print " pid is correct ...... \n";

}else {
print " pid does not exist \n";
exit 1;
}
 
J

John W. Krahn

sivga said:
how do i match a string exactly for eg

$stringid is pid-3-1

i need to match pid-[0-9*]-[0-9*] and not anything like pid-3-1-1 or
pid-3 ,pid-3-1-1-1 etc

allowed possibilities are

pid-any no of digits-any no of digits

this is the code i have but does not seem to work

if ($stringid eq 'pid-[0-9*]-[0-9*]' ) {

if ( $stringid =~ /\Apid-\d+-\d+\z/ ) {

print " pid is correct ...... \n";

}else {
print " pid does not exist \n";
exit 1;
}


John
 
T

Tad McClellan

sivga said:
i need to match pid-[0-9*]-[0-9*] and not anything like pid-3-1-1 or
pid-3 ,pid-3-1-1-1 etc


Your pattern would match

pid-*-*

is that what you want it to match?

Asterisks are not metacharacters when used inside of a character class.
 
M

Mumia W. (reading news)

Hi

how do i match a string exactly for eg

$stringid is pid-3-1

i need to match pid-[0-9*]-[0-9*] and not anything like pid-3-1-1 or
pid-3 ,pid-3-1-1-1 etc

allowed possibilities are

pid-any no of digits-any no of digits

this is the code i have but does not seem to work

if ($stringid eq 'pid-[0-9*]-[0-9*]' ) {
print " pid is correct ...... \n";

}else {
print " pid does not exist \n";
exit 1;
}

Learn Perl. Start the perldoc utility and tell it to show you the "perl"
introduction document this way:

Start->Run->"perldoc perl"

You need to look at the perlrequick document:

Start->Run->"perldoc perlrequick"

And also look at "perlintro":

Start->Run->"perldoc perlintro"

Good luck.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top