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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • poolboi
    New Member
    • Jan 2008
    • 170

    #1

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

    hey guys,

    another question for thoughts,

    i'm matching this:
    Code:
    MHI:;
    when i use
    [CODE=perl]
    if($data1 =~ /^(\s\D\D\D:.+\; )/)
    [/CODE]

    it doesn't match

    but when i use
    [CODE=perl]
    if($data1 =~ /^(\s\D\D\D:.+\; )/)
    [/CODE]

    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 16 '08, 08:25 PM. Reason: Fixed Code tag
  • nithinpes
    Recognized Expert Contributor
    • Dec 2007
    • 410

    #2
    You have posted this in a hurry! (both RE you posted are same). Anyway, In the string:

    Code:
    MHI:;
    The colon(:) is immediately followed by semi-colon(;)
    The RE in:
    [CODE=perl]
    if($data1 =~ /^(\s\D\D\D:.+\; )/)
    [/CODE]
    will try to match atleast one character between ':' and ';' , that's why it fails and the RE in
    [CODE=perl]
    if($data1 =~ /^(\s\D\D\D:.*\; )/)
    [/CODE]
    will work since it stands for 0 or more characters
    Last edited by eWish; May 16 '08, 08:27 PM. Reason: Removed quote to fix tag problem

    Comment

    • poolboi
      New Member
      • Jan 2008
      • 170

      #3
      alright.thanks once again

      Comment

      Working...