Simple RE, hard for a nubie

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
MikeAtWorley
Posts: 3
Joined: Thu Jan 29, 2009 3:03 pm

Simple RE, hard for a nubie

Post by MikeAtWorley »

I want to replace characters between fixed positions on each line of text. For example, in the following lines, I want to replace charcacters 5th trough 8th with YYYY.

Given this:
23 aad sssxxxx
faf ffee sscc ee67y
sss xees kkkpa

I neeed this:
23 aYYYYssxxxx
faf fYYYYsscc ee67y
sss YYYY kkkpa

I tried [b]^.\{5,8\}[/b] for a search RE, but it is obviously wrong. Help!!!!
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

This works for me to replace chars 5-8:
Search for: ^(.{4}).{4}
Replace with: \1YYYY

Given this:
23 aad sssxxxx
faf ffee sscc ee67y
sss xees kkkpa

Results in this:
23 aYYYYssxxxx
faf YYYY sscc ee67y
sss YYYY kkkpa

But, in your example, the second line is not replacing chars 5-8, is that a typo or is your explanatioin in error?
You have: faf fYYYYsscc ee67y

=======================================

Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
Hope this was helpful.............good luck,
Bob
MikeAtWorley
Posts: 3
Joined: Thu Jan 29, 2009 3:03 pm

Please excuse the typo.

Post by MikeAtWorley »

Bob,
You are correct, I left one character out in the output example. I hope you can suggest a RE that I can use, in spite of my typo.

Thanks,
Mike
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

He did. Have another look.
MikeAtWorley
Posts: 3
Joined: Thu Jan 29, 2009 3:03 pm

Thanks

Post by MikeAtWorley »

Bob and Ben,

Your solution works great. Thanks!!!!!

Mike
Post Reply