regex unexpected match of multiple chars in { brackets }

General questions about using TextPad

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

Post Reply
badhack
Posts: 2
Joined: Mon Mar 07, 2011 5:47 pm

regex unexpected match of multiple chars in { brackets }

Post by badhack »

Consider these two lines of code:

$gamestatscache{$player}{$svariant}{wins} = 0;
$gamestatscache{$player}{$svariant}{losses} = 0;

In Textpad 5.4.2 I want to match the "$gamestatscache{$player}{" part which did not work. To simplify the problem I tried to match "$gamestatscache{$player" with:

REGEX 1: $gamestatscache{$[:alpha:]+
REGEX 1a: $gamestatscache{$\([:alpha:]\)+

Both

MATCH 1: $gamestatscache{$pla

which is wrong, correct match would be

MATCH 1b: $gamestatscache{$player

I tried to work around the problem with

REGEX 2: $gamestatscache{$[:alpha:]+yer

which matches (somewhat consequentially)

MATCH: $gamestatscache{$player

Seeing that, I tried to go for the full nine yards with

REGEX2: $gamestatscache{$[:alpha:]+yer}

which fails (no matches).

I am not sure if I got the syntax of Textpad's regex implementation right (I am mostly using perl regexes) but this looks like a bug to me.

Thank you for looking into this
from a rather happy registered & licensed user.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

What you tried wouldn't work in Perl either. Try
\$gamestatscache{\$[[:alpha:]]+}{
or
\$gamestatscache{\$[a-z]+}{
badhack
Posts: 2
Joined: Mon Mar 07, 2011 5:47 pm

Post by badhack »

ben_josephs wrote:What you tried wouldn't work in Perl either. Try
\$gamestatscache{\$[[:alpha:]]+}{
or
\$gamestatscache{\$[a-z]+}{
Thanks, I know that Perl syntax is different ;)

I keep forgetting that [:alpha:]+ does not work in TextPad as one might expect but that they are character class operators only. Also, Textpad seems to treat $ as a normal character if the regex does not contain a preceding ^ (that's why this example also works without escaping $)

Thank you kindly for your reply, it pushed me in the right direction.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

[:alpha:]+ does not work anywhere as you expect. The notation [:alpha:] can only be used inside a character class: you must enclose it in another pair of square brackets: [[:alpha:]].

Are you sure about TextPad's handling of $? I'm using TextPad 5.3, and in that version, when Regular expression is selected, $ is treated as an end-of-line anchor, wherever it occurs (except when it's quoted or is in a character class).
Post Reply