#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Posts
    7
    Rep Power
    0

    What is matter : match rule correct?


    Requirements:
    1. It must include at least one lowercase character [a-z]
    2. It must include at least one digit \d

    Code:
    match='\b(?=[^a-z]*[a-z])(?=\D*\d)\w+\b'
    str="12AAayuA 12345 12ACB"
    echo $str |grep -oP  $match
    12AAayuA
    It seems that the match rule is correct.
    Let's try again.
    Code:
    match='\b(?=[^a-z]*[a-z])(?=\D*\d)\w+\b'
    str="12AAayuA abc  12345 12ACB"
    echo $str |grep -oP  $match
    12AAayuA
    abc
    To test echo "abc" |grep -oP $match alone,no output.
    What is the matter?
  2. #2
  3. Maddening Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,455
    Rep Power
    9645
    Both [^a-z] and \D will also match spaces. Think about it.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2017
    Posts
    7
    Rep Power
    0
    match='\b(?=[^a-z]*[a-z])(?=\D*\d)\w+\b'
    str="12AAayuA abc 12AAayuA abc"
    echo $str |grep -oP $match
    12AAayuA
    abc
    12AAayuA
    Why the second abc CAN'T matched?
  6. #4
  7. Maddening Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,455
    Rep Power
    9645
    Because
    2. It must include at least one digit \d

IMN logo majestic logo threadwatch logo seochat tools logo