Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

Using * works but using + doesn't work in matching MHI:;

Question posted by: poolboi (Familiar Sight) on May 16th, 2008 07:41 AM
hey guys,

another question for thoughts,

i'm matching this:
Code: ( text )
  1. MHI:;


when i use
Code: ( text )
  1. if($data1 =~ /^(\s\D\D\D:.+\;)/)


it doesn't match

but when i use
Code: ( text )
  1. if($data1 =~ /^(\s\D\D\D:.+\;)/)


it matches

so why is it although i know "*" matches 0 or more times and "+" matches 1 or more times
Last edited by eWish : May 16th, 2008 at 08:25 PM. Reason: Fixed Code tag
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
nithinpes's Avatar
nithinpes
Expert
205 Posts
May 16th, 2008
09:45 AM
#2

Re: Using * works but using + doesn't work in matching MHI:;
You have posted this in a hurry! (both RE you posted are same). Anyway, In the string:

Code: ( text )
  1. MHI:;

The colon(:) is immediately followed by semi-colon(;)
The RE in:
Code: ( text )
  1. if($data1 =~ /^(\s\D\D\D:.+\;)/)

will try to match atleast one character between ':' and ';' , that's why it fails and the RE in
Code: ( text )
  1. if($data1 =~ /^(\s\D\D\D:.*\;)/)

will work since it stands for 0 or more characters

Last edited by eWish : May 16th, 2008 at 08:27 PM. Reason: Removed quote to fix tag problem
Reply
poolboi's Avatar
poolboi
Familiar Sight
168 Posts
May 16th, 2008
04:31 PM
#3

Re: Using * works but using + doesn't work in matching MHI:;
alright.thanks once again

Reply
Reply
Not the answer you were looking for? Post your question . . .
170,098 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Top Perl Forum Contributors