Page 1 of 1

Regex for Ruby errors

Posted: Sat Dec 13, 2008 10:04 pm
by dwo77
Hi everybody!

I'm using Textpad to do some Ruby programming now. I tried to create a regex for parsing errors from the tool-window. I was 2/3 successful, but I need help with the rest.

A possible Ruby error output looks like this:
C:/Temp/fxrb/datatarget.rb:71:in `initialize': undefined local variable or method `zontalSeparator' for #<DataTargetWindow:0x3c03bc4> (NameError)
from C:/Temp/fxrb/datatarget.rb:176:in `new'
from C:/Temp/fxrb/datatarget.rb:176
Getting the error from the first line is no problem, but the 2nd and 3rd is quite tricky.

My regex:

Code: Select all

^\(\(\tfrom \)?[^\.]*\.rbw?\):\([0-9]+\)
In the first line I get the file in group 1 and the line in group 2, but the following lines move the groups, so file is in 2 and line in 3.

Is there a solution for this?

Posted: Sun Dec 14, 2008 12:11 am
by ben_josephs
I recommend Posix regular expression syntax, as it reduces the number of backslashes and increases readability:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Here's one way to do it (assuming Posix syntax):

Code: Select all

^(\tfrom |)([^.]*\.rbw?):([0-9]+)
The filename is in register 2; the line number is in register 3.

Posted: Sun Dec 14, 2008 8:50 pm
by dwo77
Thank you. I didn't think of using | with nothing on the right side! :lol: