By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,807 Members | 1,995 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,807 IT Pros & Developers. It's quick & easy.

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

100+
P: 170
hey guys,

another question for thoughts,

i'm matching this:
Expand|Select|Wrap|Line Numbers
  1. MHI:;
  2.  
when i use
Expand|Select|Wrap|Line Numbers
  1. if($data1 =~ /^(\s\D\D\D:.+\;)/)
  2.  
it doesn't match

but when i use
Expand|Select|Wrap|Line Numbers
  1. if($data1 =~ /^(\s\D\D\D:.+\;)/)
  2.  
it matches

so why is it although i know "*" matches 0 or more times and "+" matches 1 or more times
May 16 '08 #1
Share this Question
Share on Google+
2 Replies


nithinpes
Expert 100+
P: 410
You have posted this in a hurry! (both RE you posted are same). Anyway, In the string:

Expand|Select|Wrap|Line Numbers
  1. MHI:;
  2.  
The colon(:) is immediately followed by semi-colon(;)
The RE in:
Expand|Select|Wrap|Line Numbers
  1. if($data1 =~ /^(\s\D\D\D:.+\;)/)
  2.  
will try to match atleast one character between ':' and ';' , that's why it fails and the RE in
Expand|Select|Wrap|Line Numbers
  1. if($data1 =~ /^(\s\D\D\D:.*\;)/)
  2.  
will work since it stands for 0 or more characters
May 16 '08 #2

100+
P: 170
alright.thanks once again
May 16 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.