Simple Regex for Numeric Range


#1

Hi,

I’m trying to get a regex working in Atom for one of the grammar styles I’m using.

The existing regex is 'match': '\\b(d[1-9])\\b' which is do match d1 - d9

I’m trying to expand it to d1 through d16 which and I’ve tried a few things, I think my syntax is still off. I tried using ^([1-9]|1[0-6])$ and it didn’t work out too well.

Any suggestions?

Thanks in advance.


#2

If you check using a tool that breaks down each match, you will find that ([1-9]|1[0-6]) will match the d1 and leave the 6 behind. You can achieve the effect you want by using (1[0-6]|[1-9]).


#3

oh man thank you for that link. that tool is great!

cheers!


#4

I never write regular expressions without it.