Unexpected Regex Outcomes

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
LWatts
Posts: 2
Joined: Sun Jan 30, 2011 11:01 pm

Unexpected Regex Outcomes

Post by LWatts »

After trying to figure out why TextPad does the below, I searched the known issues of TextPad, but failed to find anything about REGEX. Could the Regex that TextPad doesn't recognize be documented in the known issues forum?

Code: Select all

Find what: [ \t\r\n]
Replace with: #
Original Text:
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Outcome:
ABCDEFGHIJKLM#OPQ#STUVWXYZ

Expected:
ABCDEFGHIJKLMNOPQRSTUVWXYZ

Code: Select all

Find what: [ \t\r\n]
Replace with: #
Original Text:
SELECT     ANID, Column1, COUNT(*) AS Count
FROM         Table
WHERE     (ANID = 1)
GROUP BY ANID, Column1
ORDER BY Column1

Outcome:
SELECT#####A#ID,#Colum#1,#COU#T(*)#AS#Cou#t
F#OM#########Table
WHE#E#####(A#ID#=#1)
G#OUP#BY#A#ID,#Colum#1
O#DE##BY#Colum#1

Expected:
SELECT#####ANID,#Column1,#COUNT(*)#AS#Count#FROM#########Table#WHERE#####(ANID#=#1)#GROUP#BY#ANID,#Column1#ORDER#BY#Column1
This likely has been true since March 2010.
ben_josephs wrote:TextPad's regex engine is old and tired, and it doesn't support non-greedy repetitions. And it doesn't recognise the notation \s as representing a white space character. Source
Edit: Corrected escape char and retested to be sure.
Last edited by LWatts on Mon Jan 31, 2011 2:09 am, edited 1 time in total.
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

The first problem is that TextPad doesn't recognise the escape sequence "\r" as a carriage return, so it simply matches "r".

The second problem is that for some reason "\n" doesn't work in a character class expression (unlike "\t"). Therefore, "[\n]" simply matches "n" or a backslash.

Incidentally, you're using forward slashes in your examples where you should be using backslashes. If that's not a typo, then there's another problem.
LWatts
Posts: 2
Joined: Sun Jan 30, 2011 11:01 pm

Post by LWatts »

ak47wong wrote:Incidentally, you're using forward slashes in your examples where you should be using backslashes. If that's not a typo, then there's another problem.
Not sure how I messed that up. Updated the escape chars and I retested the outcomes to be sure. I guess also of note I'm on TextPad 5.4.2
Post Reply