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

Sunday, November 6, 2022

[FIXED] How can I modify my regex so that it includes 1171

 November 06, 2022     regex, regex-group     No comments   

Issue

https://regex101.com/r/QTdaAT/1

My current regex matches all numbers that have 117 except for 1171. I am trying to modify the regex so that it includes 1171 1711 7111. I included a link that provides examples of the matches that are made and missed with the regex I am using. Any help will be greatly appreciated.

"\b(?=[02-9]1[02-9]1[02-9]\b)(?=\d{3})\d7\d*\b"

example:

matches 1172, 1173 1174

Needs to include 1171.


Solution

To match all numbers that contain at least two 1 and one 7

Then this simplified regex pattern will match them

\b(?=\d*1\d*1)(?=\d*7)\d+\b

The first lookahead (?=\d*1\d*1) checks for two 1 digits.
The second lookahead (?=\d*7) checks for a 7 digit.



Answered By - LukStorms
Answer Checked By - Senaida (PHPFixing Volunteer)
  • 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

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 © PHPFixing