zwitterion zwitterion - 1 year ago 122
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?

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download