Help with replacing string (wildcards?)

Post any Bulk Rename Utility support requirements here. Open to all registered users.

Help with replacing string (wildcards?)

Postby SomeNewbie » Tue Jun 14, 2011 9:46 pm

Hi, I'm new to BRU.
I need to replace a string in several files:
" xxAxx " to " AxxBxx " where "x" is a digit. For example:
35A44
to:
A35B44
(note the spaces)
I tried to replace by using DOS/Windows wildcards like so:
Replace: ??A??
With: A??B??

But that doesn't seem to work. Any ideas?
SomeNewbie
 
Posts: 1
Joined: Tue Jun 14, 2011 9:37 pm

Re: reorder parts of string (wildcards?) regex

Postby Stefan » Thu Jun 16, 2011 12:51 pm

Hi.

Always the same pattern? (anythingTillAnSpace, two digits, one char, two digits, spacePlusAnything)





OK, we try...


FROM:
xxx 35A44 xxx

TO:
xxx A35B44 xxx

USE:

RegEx(1)
match: (.+) (\d\d)(\w)(\d\d) (.+)
replace: \1 \3\2B\4 \5

Explanation:
Match the different groups (digits, char, digits) and catch them in (...)-groups which can reorder in the replacement.
(.*) match anything till an space => xxx , and can be re-used with \1
(\d\d) match two digits => 35, and can be re-used with \2
(\w) match one "word" sign => A, and can be used by \3
Add an "B" at your own, then add the last match by \4 and \5


(Yes, \4 and \5 could be one matching group only too)
match: (.+) (\d\d)(\w)(\d\d .+)
replace: \1 \3\2B\4


or even like
match: (.+ )(\d\d)(\w)(\d\d .+)
replace: \1\3\2B\4
There are many ways.


Read an regular expressions tutorial what that all means.

HTH? :D
Stefan
 
Posts: 736
Joined: Fri Mar 11, 2005 7:46 pm
Location: Germany, EU


Return to BRU Support