Page 1 of 1

changing the sequence of codes while preserving values

Posted: Mon Feb 06, 2012 11:39 am
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.

Posted: Mon Feb 06, 2012 12:48 pm
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

Posted: Mon Feb 06, 2012 12:51 pm
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.

Posted: Mon Feb 06, 2012 12:59 pm
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.

Posted: Mon Feb 06, 2012 2:07 pm
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.