2
\$\begingroup\$

I encountered a problem at http://regexone.com/example/6? You can view the problem by clicking the link. There was required a regular expression to extract the method name, filename and the line number from a particular stack trace in an android development application.

I used the following regular expression to solve the problem :

at widget.List.([a-zA-Z]+).([A-Za-z]+\.java).(\d{3,4}).

The expression works for the problem but i don't think its the correct regular expression as there is no hat(^) and dollar ($) included in it.

\$\endgroup\$

closed as unclear what you're asking by Jamal Aug 9 '15 at 20:27

Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.

  • \$\begingroup\$ If you want to actually solve the problem rather than merely pass the test cases then you also need to take into account that packages can contain multiple components separated by a dot, that all names can begin with an underscore and can contain digits except at the first character, etc. \$\endgroup\$ – Peter Taylor Mar 5 '13 at 11:50
  • \$\begingroup\$ You are falsely assuming a regex should contain ^ and $. \$\endgroup\$ – Eric Mar 5 '13 at 15:35
2
\$\begingroup\$

If you wish to include the hat ^ and dollar $ signs, then the regex can be rewritten as:

^.*\s+at widget\.List\.(\w+)\((\w+\.java)\:(\d+)\)$

Ofcourse, you can still use \d{3,4} instead of \d+ but that'll result in you missing the errors in line numbers less than 100(like 1 to 99).

Similarly, you can use \w+ in place of [a-zA-Z]+ or simply, [A-z]+ will work too.

\$\endgroup\$
  • \$\begingroup\$ Thats a perfect regular expression built by you @Back in a Flash. Good one ! \$\endgroup\$ – newDevGuy Mar 5 '13 at 11:59

Not the answer you're looking for? Browse other questions tagged or ask your own question.