changing the sequence of codes while preserving values

General questions about using TextPad

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

Post Reply
joedoll
Posts: 2
Joined: Mon Feb 06, 2012 11:23 am
Location: Paris

changing the sequence of codes while preserving values

Post by joedoll »

This seems like an easy to solve problem but I can't see a similar topic.

I need to change the sequence of codes without changing the variables in the codes. Can this be done? And if so how?

Sample of current text:

ind1=' ' ind2=' ' tag='300'>

should be replaced by:

tag='300' ind1=' ' ind2=' '>

The variables in between the '' for each part must be preserved.

Any help is very much appreciated.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

You haven't defined the problem precisely. Are the keys always initially in the same order, that is ind1, ind2, then tag?

If so, this should do it:

Use "Posix" regular expression syntax:
Configure | Preferences | Editor

[X] Use POSIX regular expression syntax
Search | Replace... (<F8>):
Find what: (ind1='[^']*') (ind2='[^']*') (tag='[^']*')
Replace with: \3 \1 \2

[X] Regular expression

Replace All
ak47wong
Posts: 703
Joined: Tue Aug 12, 2003 9:37 am
Location: Sydney, Australia

Post by ak47wong »

Here's one way to do it. First, enable POSIX regular expression syntax in Configure > Preferences > Editor.

Then do a Replace operation as follows:

Find what: ind1='(.*)' ind2='(.*)' tag='(.*)'>
Replace with: tag='\3' ind1='\1' ind2='\2'>


Select Regular expression and click Replace All.
joedoll
Posts: 2
Joined: Mon Feb 06, 2012 11:23 am
Location: Paris

Post by joedoll »

Yes, the keys are always in the same order.

Thanks to both of your suggestions. I just tried the second one and it works perfectly. It also helps me to replace the single quote for each key with double quotes, which was a second problem.
ben_josephs
Posts: 2464
Joined: Sun Mar 02, 2003 9:22 pm

Post by ben_josephs »

Be aware that using .* will cause the replacement to go wrong if there is more than one set of similar tags on a single line. This is because * is greedy: it matches as much as possible.

Moral: never use .* when [...]* or [^...]* will do.
Post Reply