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.
Share
Try this:
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”.)