Rename with Match and Replace

A swapping-ground for Regular Expression syntax

Rename with Match and Replace

Postby pruebez » Thu Mar 19, 2020 9:22 pm

I want to ask something simple before asking something more complicated.
I have a file named "test [1234].txt"

If I:
Code: Select all
Match: 1234
Replace: hi


It results in "hi.txt" instead of the expected "test [hi].txt"
Am I doing something wrong?
pruebez
 
Posts: 1
Joined: Thu Mar 19, 2020 9:18 pm

Re: Rename

Postby RegexNinja » Fri Mar 20, 2020 9:50 am

Hi,

In BRU, you have to (Group) everything you wanna keep inside parenthesis.
Anything not grouped will be lost (to let you replace it, if desired).
Just use \1, \2, \3, etc to reference your (Groups) in the replacement.

So the Match/Replace is:

(.*)1234(.*)
\1hi\2


Much more data in the new manual: http://www.bulkrenameutility.co.uk/foru ... =12&t=4743
Its material is suitable for beginners and experts alike.
Cheers!
RegexNinja
 
Posts: 34
Joined: Fri Feb 21, 2020 5:26 pm

Re: Rename with Match and Replace

Postby Admin » Sat Mar 21, 2020 1:12 am

BTW if you just need to replace a string of text with another string of text, you can use Replace (3) in BRU.
Admin
Site Admin
 
Posts: 1763
Joined: Tue Mar 08, 2005 8:39 pm

Re: Rename with Match and Replace

Postby RegexNinja » Sat Mar 21, 2020 6:45 am

Yes, I should've mentioned #3Replace! Soo used to regexing lately, lol.
The good part about #3Replace, is that it replaces all occurences of 1234.

With #1Regex, that's more difficult to achieve.
Cheers.
RegexNinja
 
Posts: 34
Joined: Fri Feb 21, 2020 5:26 pm


Return to Regular Expressions