regex query

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard

Post Reply
larnapairce
Posts: 3
Joined: Tue Aug 12, 2003 2:39 pm

regex query

Post 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
User avatar
webmasta
Posts: 168
Joined: Mon Jul 28, 2003 8:16 pm
Location: Toronto

Post 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.
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post 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
Last edited by Bob Hansen on Wed Aug 13, 2003 2:56 pm, edited 1 time in total.
larnapairce
Posts: 3
Joined: Tue Aug 12, 2003 2:39 pm

Post by larnapairce »

Appreciate the replies from webmasta & Bob Hanson.

Great little solutions. Cheers.
Post Reply