Home > Software engineering >  Regex for number-X-number such as "100x100", "350X200", etc
Regex for number-X-number such as "100x100", "350X200", etc

Time:05-19

I need a php regex expression to catch a pattern number/x/number strings.

Examples of strings that would be valid:

"100x100"
"350x200"
"1x2000"

... etc

Examples of strings that would NOT be valid:

"100"
"absx200"
"x35"

... etc

I am trying:

/^[\w-_.]*$/

But it is not working. Please help

CodePudding user response:

\d x\d 

Should do the trick.

\d is for digits and means 1 or more. x means x and the rest is a repeat of the first two commands. Basically 1 or more digit followed by an x followed by one or more digits.

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

  • Related