Regex for Ruby errors

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
dwo77
Posts: 4
Joined: Sat Dec 13, 2008 9:54 pm

Regex for Ruby errors

Post 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?
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post 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.
dwo77
Posts: 4
Joined: Sat Dec 13, 2008 9:54 pm

Post by dwo77 »

Thank you. I didn't think of using | with nothing on the right side! :lol:
Post Reply