The global modifier

Changing special characters to underscores

Lets say you have a stack of documents that you need to upload to a webserver but the filenames contain spaces and other characters that make it difficult to link to (eg, a%20file%20with%20spaces.pdf):

Using the Global modifier, RegexRenamer can perform multiple replacements on each file. In this case, we want to replace each space or # character with an underscore.


Step 1: In RegexRenamer, browse to the folder containing the files.

CLICK TO ENLARGE

Step 2: Type the following regex in the Match field: [ #] (match either a space or a # character).

CLICK TO ENLARGE

Step 3: Type a single underscore in the Replace field: _.

CLICK TO ENLARGE

Step 4: Check the /g checkbox to enable the global modifier.

CLICK TO ENLARGE

Step 5: Click the Rename button to apply the changes.

CLICK TO ENLARGE

Now the files don’t contain any special characters and can be easily linked to:


Note: If you wanted to group consecutive characters together and replace them with a single underscore, simply add a + at the end of the Match pattern (which means match the previous element one or more times, as many as possible).