Match and replace 2 characters? 1 set and 1 flexible?

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
wires
Posts: 3
Joined: Tue Jul 26, 2011 12:37 pm

Match and replace 2 characters? 1 set and 1 flexible?

Post by wires »

Is it possible to match a specific character and any single character then replace both characters with the uppercase version of the single character? Here is an example:
starting string: -axx-bxxx-9xxx-c
resulting string: AxxBxxx9xxxC

I have a files with auto-generated contents that needs to be converted in the way described above and right now I'm stuck making the conversions by hand. It would help me out a great deal to be able to make all the replacements at once. Thank you.
ben_josephs
Posts: 2464
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: \u\1

[X] Regular expression

Replace All
wires
Posts: 3
Joined: Tue Jul 26, 2011 12:37 pm

Question clairification

Post by wires »

Thank you! Your answer worked like a charm. Unfortunately I didn't phrase my question correctly. The files I need to perform the text replacements on are XML and the text that needs to be replaced are just in name="" tags so a better example is:
<bind-xml name="interchange-control-trailer" node="element" reference="false"/>

and the outcome needs to be:
<bind-xml name="interchangeControlTrailer" node="element" reference="false"/>

I did some research on Posix regular expressions and the best that I was able to come up with is:
find what: name="[a-zA-Z0-9]-(.)"
Replace with: name="\u\1"

But that doesn't work. Can you help me once more?



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

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

[X] Regular expression

Replace All
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Find what: name="([a-z0-9-]+)-([a-z0-9]+)"
Replace with: name="\1\u\2"

[X] Regular expression

Replace All -- do this repeatedly until it beeps
wires
Posts: 3
Joined: Tue Jul 26, 2011 12:37 pm

Question answered!

Post by wires »

It worked like a charm. That saves me a ton of time. You are awesome. Thank you very much.
ben_josephs wrote:
Find what: name="([a-z0-9-]+)-([a-z0-9]+)"
Replace with: name="\1\u\2"

[X] Regular expression

Replace All -- do this repeatedly until it beeps
Post Reply