I'm now working on a (f)lex scanner, and when I want handle the numbers using regex as follows:
(\B[+-]?[0-9]+)|([0-9]+)
and the match requirements(the result I want) are as the picture shown:
we can see that the greens and reds are match cases(for the first and second condition).This "experiment" is done at https://regex101.com/.
However when I tried to apply the above regex in lex, it does not work.
I have done some research on the reasons and alternative but they doesn't fit my needs:
- The answer of this explanined why the regex above not working
- This answer provide an alternative for similar cases, which may give you some ideas.
I hope someone could give me some ideas. Thank you!