0

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?

izash
  • 51
  • 5

1 Answers1

0

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:]* )*
Matin Zivdar
  • 593
  • 5
  • 20
  • Thanks for the reply! I have a question. I wanted to get Strings (i..e starts with " and ends with " and then has escape chars in the middle. How do I do that? Do i add /* at the start and end? – izash Feb 17 '22 at 00:29
  • Oh, I think you should use something like this `StringLiteral = \"[^(\\n|\\r)]~\"`. @izash – Matin Zivdar Feb 17 '22 at 00:56
  • So that would get any string with both a starting " and ending ". It doesnt find if theres any escape chars in the middle. So I couldn't do Regex = ( {StringLiteral}+[:jletterdigit:]* {EscapeChar}+ [:jletterdigit:]* {StringLiteral}+)*. See the problem? – izash Feb 17 '22 at 01:00