Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regex validation for custom command format

I need to validate some commands with the format similar to this

"/a foo.bar /b bar.foo /c 01(.01)"

where the final (.01) is optional (brackets are there to mark the contents as optional). Any digits can be set instead of the 0's and 1's. Also the switches /a, /b, /c are fixed For the moment, I've developed this regular expression:

@"/a\s*([\w\W]*)\s*/b\s*([\w\W]*)\s*/c\s*[0-9,0-9,(.,0-9,0-9){0,1}]

but for some reason, if the command is for example

"/a foo.bar /b bar.foo /c 01.", 

it still validates against the regex. Valid commands should end either with 2digits.2digits or simple 2digits.

Can someone help me to get this fixed?

Cheers,

Alex Barac

like image 763
Alex Barac Avatar asked Mar 28 '26 16:03

Alex Barac


1 Answers

Try this one:

^/a\s*(.*)\s*/b\s*(.*)\s*/c\s*((\d{2}\.\d{2})|(\d{2}))$

Regular expression visualization

Debuggex Demo

like image 144
Alex Filipovici Avatar answered Apr 02 '26 19:04

Alex Filipovici



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!