0

I'm trying to create regex that will match integer value which starts from -2,147,483,648 to 2,147,483,647. As I noticed, JFlex not support \w, \d, ^, $.

I tried to write some regex like this in flex file. It compiles, but not working.

INTEGER = (0|[1-9]{1}[0-9]{0,8}|[1]{1}[0-9]{1,9}|[-]{1}[2]{1}([0]{1}[0-9]{8}|[1]{1}([0-3]{1}[0-9]{7}|[4]{1}([0-6]{1}[0-9]{6}|[7]{1}([0-3]{1}[0-9]{5}|[4]{1}([0-7]{1}[0-9]{4}|[8]{1}([0-2]{1}[0-9]{3}|[3]{1}([0-5]{1}[0-9]{2}|[6]{1}([0-3]{1}[0-9]{1}|[4]{1}[0-8]{1}))))))))|(\+)?[2]{1}([0]{1}[0-9]{8}|[1]{1}([0-3]{1}[0-9]{7}|[4]{1}([0-6]{1}[0-9]{6}|[7]{1}([0-3]{1}[0-9]{5}|[4]{1}([0-7]{1}[0-9]{4}|[8]{1}([0-2]{1}[0-9]{3}|[3]{1}([0-5]{1}[0-9]{2}|[6]{1}([0-3]{1}[0-9]{1}|[4]{1}[0-7]{1})))))))))

Is there any possible way to do that? Or maybe there is some easier way to create such regex?

Edit:

I found regex for this from this question: Regex for a valid 32-bit signed integer

Regex is:

\b([0-9]{1,9}|1[0-9]{9}|2(0[0-9]{8}|1([0-3][0-9]{7}|4([0-6][0-9]{6}|7([0-3][0-9]{5}|4([0-7][0-9]{4}|8([0-2][0-9]{3}|3([0-5][0-9]{2}|6([0-3][0-9]|4[0-7])))))))))\b|-\b([0-9]{1,9}|1[0-9]{9}|2(0[0-9]{8}|1([0-3][0-9]{7}|4([0-6][0-9]{6}|7([0-3][0-9]{5}|4([0-7][0-9]{4}|8([0-2][0-9]{3}|3([0-5][0-9]{2}|6([0-3][0-9]|4[0-8])))))))))\b

I removed \b in .bnf and .flex also.

This regex is compiles well in .bnf file, .flex generates class without error's, but nothing work's. I tested this regex in both online tests:

flex regex test

regex test

But in test's everything is fine. Where did I made a mistake?

ROBO-KY
  • 37
  • 8
  • What's the point of using `{1}`? It's 100% noise, as far as I can see. (And writing `[1]` instead of `1` is marginal, as well.) – rici Mar 13 '20 at 01:09
  • @rici thank you for your comment. I removed that, but nothing works still. – ROBO-KY Mar 13 '20 at 09:48

1 Answers1

0

Well, the correct regex for that was:

([0-9]{1,9}|1[0-9]{9}|2(0[0-9]{8}|1([0-3][0-9]{7}|4([0-6][0-9]{6}|7([0-3][0-9]{5}|4([0-7][0-9]{4}|8([0-2][0-9]{3}|3([0-5][0-9]{2}|6([0-3][0-9]|4[0-7])))))))))|-([0-9]{1,9}|1[0-9]{9}|2(0[0-9]{8}|1([0-3][0-9]{7}|4([0-6][0-9]{6}|7([0-3][0-9]{5}|4([0-7][0-9]{4}|8([0-2][0-9]{3}|3([0-5][0-9]{2}|6([0-3][0-9]|4[0-8])))))))))

I was inattentive. I didn't noticed one more \b in regex.

ROBO-KY
  • 37
  • 8