0

Can someone help me build a regex that can check four blocks containing text and numbers separated by hyphens?

I'm trying the following:

/([a-z0-9]{4,10})-([a-z0-9]{4,10})-([a-z0-9]{4,10})-([a-z0-9]{4,10})/

It works for: 12345-1234-1b3456-12c4567e910 and for abc1-ab2de-ab4def-abcdef0

But it's also working for: 12345-1234-1b3456-1234567891011

I need the regex to be invalid when this outside any of the 4 blocks (minimum 4 and maximum 10).

V.Salles
  • 403
  • 2
  • 9
  • 16
  • Wrap the pattern in `/^...$/` to [make it match](https://regex101.com/r/kZN7MQ/1) if only the whole string matches it. As of now, the pattern matches [just a portion of string](https://regex101.com/r/wIk3SC/1) in the 2nd case. – raina77ow Jun 18 '21 at 23:37
  • 1
    Thank U, I'm a regex newbie =). – V.Salles Jun 18 '21 at 23:45
  • Closed as duplicate; while the original question was about JS regex, and this one is about PHP regex, the boundary anchors are actually supported universally. And yes, you're welcome. ) – raina77ow Jun 18 '21 at 23:47

0 Answers0