Chris
Chris

Reputation: 65

Regex starting with 5, excluding specific preceding numbers, and 6 characters in length

I beseech thee, oh gods of the mighty RegEx... hear my plee!!!

I need a Regex for the following rules

  1. -Number has to be 6 characters long

  2. -Number has to start with 5

  3. Number cannot start with "50****" or "589***"(It can start with 51, 52, 587, 583, etc...)

What I'm working off of right now is

^5(?!(0\b|89\b))\d+\b.

Please HELP!!!

Upvotes: 2

Views: 33

Answers (1)

vks
vks

Reputation: 67968

^5(?!(?:0|89))\d{5}$

This should do it for you.See demo.

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

You dont need \b after 0 or 89 as you dont expect a word boundary there.

Upvotes: 2

Related Questions