Home > Back-end >  Correct regex expression for including whitespace within a match only
Correct regex expression for including whitespace within a match only

Time:10-21

I have this sample of string Lorem ipsum 12 121 323 454 dolor sit amet. Here is my RegEx ([0-9 ?\s]) but it includes outside spaces.

enter image description here

CodePudding user response:

Start with a nonspace and end with nonspace:

[0-9 ](?:([0-9 ?\s]*[0-9 ]))?

A digit or a plus, followed optionally by any number of digits, plusses or spaces, finally ending in a digit or a plus.

  • Related