RegEx Replace All not replacing all matches

General questions about using TextPad

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

Post Reply
danny
Posts: 6
Joined: Fri Jan 13, 2023 12:57 am

RegEx Replace All not replacing all matches

Post by danny »

I am using TextPad 8.23.2

I have this string.

Code: Select all

, (A01, B01), (A02, B02), (A03, B03), (A04, B04), (A05, B05), (A06, B06), (A07, B07), (A08, B08), (A09, B09), (A10, B10), (A11, B11), (A12, B12)
I want to use find & replace with regular expression to make this.

Code: Select all

OR (sty.CODE = 'A01' AND clr.CODE = 'B01')
OR (sty.CODE = 'A02' AND clr.CODE = 'B02')
OR (sty.CODE = 'A03' AND clr.CODE = 'B03')
OR (sty.CODE = 'A04' AND clr.CODE = 'B04')
OR (sty.CODE = 'A05' AND clr.CODE = 'B05')
OR (sty.CODE = 'A06' AND clr.CODE = 'B06')
OR (sty.CODE = 'A07' AND clr.CODE = 'B07')
OR (sty.CODE = 'A08' AND clr.CODE = 'B08')
OR (sty.CODE = 'A09' AND clr.CODE = 'B09')
OR (sty.CODE = 'A10' AND clr.CODE = 'B10')
OR (sty.CODE = 'A11' AND clr.CODE = 'B11')
OR (sty.CODE = 'A12' AND clr.CODE = 'B12')
This is what I am using for the Replace dialog.

Find:

Code: Select all

, \(([^,]+), ([^)]+)\)
Replace:

Code: Select all

\nOR \(sty.CODE = '$1' AND clr.CODE = '$2'\)
When I click Replace All I get below result.

Code: Select all

OR (sty.CODE = 'A01' AND clr.CODE = 'B01')
OR (sty.CODE = 'A02' AND clr.CODE = 'B02'), (A03, B03)
OR (sty.CODE = 'A04' AND clr.CODE = 'B04'), (A05, B05), (A06, B06)
OR (sty.CODE = 'A07' AND clr.CODE = 'B07'), (A08, B08), (A09, B09), (A10, B10)
OR (sty.CODE = 'A11' AND clr.CODE = 'B11'), (A12, B12)
I was expecting all the matches would be replaced. TextPad replaced some matches but not all the matches.
Last edited by AmigoJack on Wed Oct 22, 2025 10:44 pm, edited 1 time in total.
Reason: formatting as code
User avatar
AmigoJack
Posts: 596
Joined: Sun Oct 30, 2016 4:28 pm
Location: グリーン ヒル ゾーン
Contact:

Re: RegEx Replace All not replacing all matches

Post by AmigoJack »

Cannot reproduce with 8.4.2x64 - I get the expected output. As a temporary workaround you could click the "Replace All" button multiple times until there are no matches anymore.
danny
Posts: 6
Joined: Fri Jan 13, 2023 12:57 am

Re: RegEx Replace All not replacing all matches

Post by danny »

Confirmed each time re-clicking Replace All button replaces more matches until there are none. Thank you for trying to reproduce and for the workaround.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Re: RegEx Replace All not replacing all matches

Post by ben_josephs »

I can reproduce this in TextPad 8.23.0.
It appears that the newline in the replacement text is causing TextPad problems.

For example, using the input test

Code: Select all

12
123
the replacment

Code: Select all

Find what: .
Replace with: $0_

X Regular expression

Replace All
correctly produces

Code: Select all

1_2_
1_2_3_
whereas

Code: Select all

Repace with: [b][color=blue]$0\n
which should produce

Code: Select all

1
2

1
2
3
in fact incorrectly prodcues

Code: Select all

1
2
1
23
User avatar
bbadmin
Site Admin
Posts: 1019
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Re: RegEx Replace All not replacing all matches

Post by bbadmin »

This will be fixed in the next release. Thanks for reporting it.
Post Reply