Saturday, August 1, 2009

Use of regular expression to find text in Eclipse

Problem

Find text inside Eclipse as the following standard:

  • starting with a given set of characters. th for example;
  • having zero or one line break inside the text;
  • having in the end a semicolon “;

Examples of expressions:

throw new RuntimeException(".newQuery() não implementado");

throw new RuntimeException(
". newQuery() não implementado");


Solution



Execute the search in Eclipse using the following regular expression: th.*\R?.* Explanation:




  • “th” – the text must star with th;


  • “.” – the point indicates that any character could be in this position;


  • *” – Asterix indicates that the previous character may appear any number of times. As the previous character is a point then the entire line will be select;


  • \R” – indicates that in this position is a line break;


  • ?” – the previous character may appear zero or once. So the text may or may not have a line break in the middle;


  • .*” – already explained;


  • ;” – the end character must be a semicolon

No comments:

Post a Comment