zwitterion zwitterion - 7 months ago 41
Javascript Question

REGEX pattern for javascript

I have this pattern to be tested in javascript using REGEX:


where n can be any integer between 0-9.

And I have this regex that works.


Is there another more elegant way to rewrite this expression to grab the same pattern?


There's a few possible simplifications:

[0-9] -> \d
[.] -> \.
[-] -> -
nnn.nnn. -> (\d{3}\.){2}

nn.nnn.nnn./nnnn-nn -> \d{2}\.(\d{3}\.){2}\/\d{4}-\d{2}

Your pattern asks for 4 digits at the end, but not your data sample. I followed the sample.