Jflex Regular expression for string with escaped characters

349 Views Asked by At

I am generating lexical analyzer with JFLEX. I need to find all strings which containing escaped characters using regular expressions. I'm struggling with this. What could it be?

1

There are 1 best solutions below

3
Matin Zivdar On

I recommend you to read Jflex manual. I think you can add any escape characters you want to the grammar like this code.

EscapeChar = \r | \n | \r\n | \t | \b                        //add more ...
Regex = ( [:jletterdigit:]* {EscapeChar}+ [:jletterdigit:]* )*

You can also use Unicode compliances either for all things that start with \ but I'm not sure if it's a good way.

EscapeChar = \u005 [:jletter:]
Regex = ( [:jletterdigit:]* {EscapeChar}+ [:jletterdigit:]* )*