Home > database >  Regular expression to match digits
Regular expression to match digits

Time:09-28

My test string:

Continuity:pass_mV[12]#x_u_123

My regular expression:

(?P<VOL>.*):.*(?P<DIGIT>[\d] )]#(?P<PIN>.*)$

My matches:

VOL Continuity
DIGIT   2
PIN x_u_123

My intention matches:

VOL Continuity
DIGIT   12
PIN x_u_123

The digits in the bracket should only be 1 or 2.

Can somebody help with modifying my regular expression to achieve this?

CodePudding user response:

Basically, change .*([\d] )] to .*\[(\d ).*:

(?P<VOL>.*):.*\[(?P<DIGIT>\d ).*#(?P<PIN>.*)$

See live demo.

CodePudding user response:

Try this one:

(?P<VOL>.*):.*\[(?P<DIGIT>[1-2] )\]#(?P<PIN>.*)$
  • Related