tags:

views:

160

answers:

3

I am developing a simple translator from MathML to Latex, using Lex and Yacc. In my lex file containing the regex rules I have one defined for arithmetic operators [-+*=/]. I want to extended so that it would recognize plus-minus (+-) and invisible times ('&InvisibleTimes'), but I'm unfamiliar with regex and I need some help.

+2  A: 

Would something like this work?

(?:[-+*=/]|\+-|&InvisibleTimes)
Copas
A: 

Try this:

([-+*=/]|\+-|&InvisibleTimes)

Note that you need to escape the + in +- because it's an operator outside of character classes. You can do this with backslash (as I've done here) or with double quotes. (The double-quote syntax is pretty unusual -- most other regex implementations only use backslash for escaping, so I'd be inclined to use backslashes as it makes the regex more "conventional".)

Laurence Gonsalves
A: 
Zifre