Page 1 of 1

replace with regular expressions

Posted: Fri Apr 27, 2012 11:37 am
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.

Posted: Fri Apr 27, 2012 1:21 pm
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

Is This Replacement Possible?

Posted: Mon Apr 08, 2013 5:23 am
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 ).

Posted: Mon Apr 08, 2013 7:23 am
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)

Posted: Mon Apr 08, 2013 7:33 am
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.