PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 6, 2022

[FIXED] How to get the match for the following use cases from this regex pattern?

 November 06, 2022     javascript, regex, regex-group, regex-lookarounds     No comments   

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 Demo

RegEx Details:

  • (?<!\d): Make sure that previous character is not a digit
  • (?!000|666|9): Make sure that we don't have 000 or 666 or 9 at the next position
  • (order\W?number)?: Match order and number optionally separated with a non-word character
  • \W*: Match 0 or more non-word characters
  • (?<!x): Make sure previous character is not x
  • \d{3}: Match 3 digits
  • [ .=-]{0,10}: Match 0 to 10 instances of given separators
  • (?!000): Make sure we don't have 000 at next position
  • \d{3}: Match 3 digits
  • [ .=-]{0,10}: Match 0 to 10 instances of given separators
  • (?!000): Make sure we don't have 000 at next position
  • \d{3}: Match 3 digits


Answered By - anubhava
Answer Checked By - Mildred Charles (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

1,213,330

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © 2025 PHPFixing