Page 1 of 1
Simple RE, hard for a nubie
Posted: Thu Jan 29, 2009 3:40 pm
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!!!!
Posted: Thu Jan 29, 2009 4:25 pm
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
-----------------------------------------
Please excuse the typo.
Posted: Thu Jan 29, 2009 4:44 pm
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
Posted: Thu Jan 29, 2009 4:52 pm
by ben_josephs
He did. Have another look.
Thanks
Posted: Thu Jan 29, 2009 7:22 pm
by MikeAtWorley
Bob and Ben,
Your solution works great. Thanks!!!!!
Mike