Another Replace method with text and numbers

Advanced Renamer forum
#1 : 20/03-22 00:48
LennY Schram
Posts: 1
Another Replace method with text and numbers:


Cause the original version posted, didn't somehow work out for me:

The explanation is simple and good, tho the "dot" (search for any character) not so for me.

my problem looked like this: ' blah blah blah 1234 blah.txt '

The solution I came up with after some tweaking:

Text to be replaced: (\w+) (\d+) (\w+) added an extra space on the end
Then replace with: \1 \3 \2 Also with an extra space added at the end

Mark the Use regular expression and apply to name.

\w used for the word(s)
\d used for the numbers

Somehow i needed the space (as for me this work now)


I would like to thank the original poster for the insight.



--------------
Original post
--------------


Text to be replaced: (.+) (.+) (.+)
Replace with: \1 \3 \2
Use regular expressions: Tick

Quick Summary:
Define three groups (that's what the bracket pairs are for).
Group 1: '(.+)' - the left group means look for any character (the dot), and repeat at least once (the '+' means one or more).
Group 2: '(.+)' - the middle group means the same thing.
Group 3: '(.+)' - the right group means the same thing again.

However, regex is greedy so Group 1 will continue to grab as much as it can stopping only when there is the absolute minimum left over to satisfy the remainder of '<space> + Group 2 + <space> + Group 3'.

This means that Group 1 will contain:
Example 1: 'hello my friend, how are you ! -'
Example 2: 'God does not play dice - 1926'

and leave Groups 2 and 3 respectively as:
Example 1: 'Bugs' and 'Bunny'
Example 2: 'Albert' and 'Einstein'

Then we take the first group and then swap the second and third groups with this:
'\1 \3 \2'