Regex word boundary alternative for lex

160 views Asked by At

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:

the result I want

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:

  1. The answer of this explanined why the regex above not working
  2. This answer provide an alternative for similar cases, which may give you some ideas.

I hope someone could give me some ideas. Thank you!

0

There are 0 answers