replace with regular expressions

General questions about using TextPad

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

Post Reply
naxshio
Posts: 3
Joined: Wed Dec 15, 2010 5:50 pm

replace with regular expressions

Post by naxshio »

Hello,

I would like to change several strings at the same time I don´t figure it out. I have, for example these two different strings in the same text file:

dlc1.2a.$07
dlc2.2a.$07

The goal is to replace them with the same name except the the first "." character in only one step using regular expressions, the result should be:

dlc12a.$07
dlc22a.$07

Thank you very much.
ben_josephs
Posts: 2461
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Search | Replace... (<F8>):
Find what: ^([^.]*)\.
Replace with: \1

[X] Regular expression

Replace All
IconMatrix
Posts: 5
Joined: Tue Jun 12, 2012 5:34 pm
Contact:

Is This Replacement Possible?

Post by IconMatrix »

I'm new at figuring out replacement expressions so any help getting
me going with this would be most appreciated.

I've tried a bunch of things in the help files, but there isn't much on
how to combine regular expressions with segments of existing code
to identify where to start and stop the regex, so I keep getting the
"not found" alert when I run the search and replace. What I want to do is:

Search For: ST2('SomeText-01a')
And replace it with: ST2(this.id)

EXAMPLE OF MY STUPIDITY: I tried to find ST2('[:alpha:]-01a') to remove "any letters" ... but I obviously don't know what I'm doing ... help!

I have over 300 replacements to make and each example of "SomeText" represents a different text string.

I've gotten to the point now where I need to

Search For: ST2(this.id)SomeText-01a')"
And need to replace the part: SomeText-01a') with nothing ( remove it ).
User avatar
bbadmin
Site Admin
Posts: 879
Joined: Mon Feb 17, 2003 8:54 pm
Contact:

Post by bbadmin »

To tackle your original problem:

Search For: ST2('SomeText-01a')
And replace it with: ST2(this.id)

The regular expression needs to eat everything between the literal brackets:

ST2\([^)]+\)

so everything that was matched can be replaced with:

ST2(this.id)
IconMatrix
Posts: 5
Joined: Tue Jun 12, 2012 5:34 pm
Contact:

Post by IconMatrix »

bbadmin wrote:To tackle your original problem:

Search For: ST2('SomeText-01a')
And replace it with: ST2(this.id)

The regular expression needs to eat everything between the literal brackets:

ST2\([^)]+\)

so everything that was matched can be replaced with:

ST2(this.id)
Most Excellent!
358 Big Thank Yous in about .8 secs :D
I'll study this and learn from it too.
Post Reply