Page 1 of 1

regex query

Posted: Tue Aug 12, 2003 3:08 pm
by larnapairce
I'm trying to do a simple find and replace BUT I need to restrict
it to a specific column.

e.g replace all 7's with 6's in column 252.

I couldn't figure it out so I did it via a macro instead.

Still very curious how it should be done.

Perl would do it via something like : $temp =~ s/(.{251})7(.*)/$1 6 $2/;

Is it along those lines ?
Appreciate any suggestions
thanks

Posted: Tue Aug 12, 2003 5:01 pm
by webmasta
Use block cursor, select column 252 from top to bottom of document, find /replace in selected text.

If using a macro then ull have to keep changing the macro column if column requirements change?? lets say if you want to change now in column 10.

Posted: Tue Aug 12, 2003 7:00 pm
by Bob Hansen
Hello larnapairce....................

Need to replace all 7s in column 252 with 6s?

:idea: Try this:

Search for: \(^.\{251\}\)7
Replace with: \16

================================
Explanation of RegEx Search Section: :arrow:
\( = beginning of first grouping to isolate
^ = start at beginning of line
. = any character, space, etc.
\{251\} = exact number of previous character (.)
\) = end of first grouping
7 = digit seven

=============================
Explanation of RegEx Replace Section: :arrow:
\1 = first group in Search Section
6 = digit 6

Common English:
Starting at the beginning of the line, look for a group of any 251 characters followed immediately with a 7. Replace that group with the same information followed by a 6.

OR

Replace any 7 in column 252 with a 6.

=============================
Hope this helps...........good luck, :D

Bob

Posted: Wed Aug 13, 2003 8:23 am
by larnapairce
Appreciate the replies from webmasta & Bob Hanson.

Great little solutions. Cheers.