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!!!!
Simple RE, hard for a nubie
Moderators: AmigoJack, bbadmin, helios, MudGuard
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
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
-----------------------------------------
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
Bob
-
MikeAtWorley
- Posts: 3
- Joined: Thu Jan 29, 2009 3:03 pm
Please excuse the typo.
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
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
-
MikeAtWorley
- Posts: 3
- Joined: Thu Jan 29, 2009 3:03 pm
Thanks
Bob and Ben,
Your solution works great. Thanks!!!!!
Mike
Your solution works great. Thanks!!!!!
Mike