.*? (lazy star) regular expression not working?

General questions about using TextPad

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

Post Reply
aka_bigred
Posts: 6
Joined: Wed Nov 04, 2009 3:37 pm

.*? (lazy star) regular expression not working?

Post by aka_bigred »

I've got a quandary - a regex doesn't seem to find something in TextPad, but when I run it through another online checker, it works exactly as expected.

The file is a tilde separated text file and I'm trying to capture columns 84,85,87,88,90,91. I've masked the data as 'x' all except the columns I'm trying to capture in TextPad.

When I use this online REGEX testing tool, it captures the groups spot on, but when I use TP, it wants to match the whole line. It seems to me like TP isn't honoring the lazy star quite right. I could be wrong, but I'm a bit confused:

Here's my regex:
^(.*?~){83}(.*?)~(.*?)~.*?~(.*?)~(.*?)~.*?~(.*?)~(.*?)~

Here's a sample string:
xxxxxxxx~xxxxxxxx~~xxxxx~xxxxxxx~xxxxxxxx~xxxxxxxxxxxxxxxxxxxxxxxxxxx~xxxxxx~xxxxxxxxxxxxxxxxxxxxxx~~~x~xxxxxxxxxxxxxxxxxxxx~xxxxxx~xxxxxxxxxxxxxxxxxxxxxx~xxxxxx~xxxxxxxxxx~~xxxxxxxx~~~~~~~~~~~~~~~~~~xxx~xxxxxxxxxx~~~~~~~xxxxxxx~~~~~~~xxxxxxxx~~xxxxxxxxxxxxxxxxxxx~xxxx~~x~x~x~~x~x~x~x~~xxxxxxxx~x~x~~~xxxxxxx~~~~~~~~~~~~~L~000500.000~~G~000600.000~~H~000700.000~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xxxxxx~xxxxxxxxxxxxxxxxxx~xxxxxxxx~xxxx~~xxxxxxxx~xxxxxxxxxxxxxxxxxxxxxxxxxxx~xxxxxxx~xxxxxxxxxxxxxxxx~~~~~~~~~~~~~~~~~x~x~xxxxxxxx~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xxxxxxxxxx~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~xxxxxxxxxxx~xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx~~~xxxxxxxxxxx~xxxxxxxxxxxxxxxxxxxxxxxxxxxx~xxxxx~xxxxxxxxxxxxxxxxxxxxxxxx~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~xxxxxxxxxx~xxxxxxxxxxxxxxxxxxx~~~~~~~~~~~~~~~~~~~~xxxxxxxxxxxxxxx~~


Groups \2,\3,\4,\5,\6 are what I'm looking for

Any suggestions?

FYI - I'm using POSIX regex mode
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

TextPad's regex engine is old and doesn't support non-greedy repetition operators. Try this instead:
^([^~]*~){83}([^~]*)~([^~]*)~[^~]*~([^~]*)~([^~]*)~[^~]*~([^~]*)~([^~]*)~
It's a better way to do it anyway.
Post Reply