2024 © RegexOne
Email |
Twitter
In this example, we are going to use actual output from an Android adb debugging session. Your goal is to use any regular expression techniques that we've learned so far to extract the filename, method name and line number of line of the stack trace (they follow the form "at package.class.methodname(filename:linenumber)").
Good luck!
Task | Text | Capture Groups | |
skip | W/dalvikvm( 1553): threadid=1: uncaught exception | ||
skip | E/( 1553): FATAL EXCEPTION: main | ||
skip | E/( 1553): java.lang.StringIndexOutOfBoundsException | ||
capture | E/( 1553): at widget.List.makeView(ListView.java:1727) | makeView ListView.java 1727 | |
capture | E/( 1553): at widget.List.fillDown(ListView.java:652) | fillDown ListView.java 652 | |
capture | E/( 1553): at widget.List.fillFrom(ListView.java:709) | fillFrom ListView.java 709 |
Solution | This one can be tricky too, but we really just want to capture the method name, filename, and line number. This can be achieved using the expression (\w+)\(([\w\.]+):(\d+)\) in which the first capture group is the method, followed by an escaped parenthesis, followed by the filename, a colon, and finally the line number. |