Issue
I have the Regex to match the following patterns,
Link to the Use case: https://regex101.com/r/wnp1k4/1
How can i get the match for the same by modifying the Regex? please help.
(?:^|(?<=[\D;a-zA-Z(),.:;?!"'`>]))(?!000|666|9)(?<![Oo][Rr][Dd][Ee][Rr].)(?<![Oo][Rr][Dd][Ee][Rr]..)(?<![Oo][Rr][Dd][Ee][Rr]...)(?<![Oo][Rr][Dd][Ee][Rr].[Nn][Uu][Mm][Bb][Ee][Rr].)(?<![Oo][Rr][Dd][Ee][Rr].[Nn][Uu][Mm][Bb][Ee][Rr]..)(?<![Oo][Rr][Dd][Ee][Rr].[Nn][Uu][Mm][Bb][Ee][Rr]...)(?<![Xx])\d{3}[ -.=\n\r]{0,10}(?!00)\d{2}[ -.=\n\r]{0,10}(?!0000)\d{4}(?:$|(?=[\Da-zA-Z(),.:;?!"'`<= ]))
Order numbers should not get detected if 'X or x' precedes the number. so this is working fine.
x123456789
X123456789
x123-456-789
X123-456-789
123-456-789
Need to modify the regex pattern to get the match for the list of ordernumbers written like below...along with the word (order number) should be case insensitive.
ordernumber123-456-789
order number123-456789
order number 123456789
123-456789
123456789
ordernumber-123456787
ordernumber - 123456789
ordernumber #123456789
ordernumber anysplcharacter123456789
Solution
Converting my comment to answer so that solution is easy to find for future visitors.
You may use this regex:
(?<!\d)(?!000|666|9)(order\W?number)?\W*(?<!x)\d{3}[ .=-]{0,10}(?!000)\d{3}[ .=-]{0,10}(?!000)\d{3}
RegEx Details:
(?<!\d)
: Make sure that previous character is not a digit(?!000|666|9)
: Make sure that we don't have000
or666
or9
at the next position(order\W?number)?
: Matchorder
andnumber
optionally separated with a non-word character\W*
: Match 0 or more non-word characters(?<!x)
: Make sure previous character is notx
\d{3}
: Match 3 digits[ .=-]{0,10}
: Match 0 to 10 instances of given separators(?!000)
: Make sure we don't have000
at next position\d{3}
: Match 3 digits[ .=-]{0,10}
: Match 0 to 10 instances of given separators(?!000)
: Make sure we don't have000
at next position\d{3}
: Match 3 digits
Answered By - anubhava Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.