I have several html files (source code) which contain lots of text and include the code of many reports files linked to.
I need to replace every space (
) in the filenames by the undescore sign (_
). This replace must not affect the rest of the text.
The links all follow the same folder structure, but the filenames are all very different except their extension (.pdf)
For example, I have:
Please find the presentations:
href="/Portals/12/Documents/GE-Project/Amalty-WS/Joanna_POT Pb paint health econ env_RUS.pdf">Presentation 1
I need:
Please find the presentations:
href="/Portals/12/Documents/GE-Project/Amalty-WS/Joanna_POT_Pb_paint_health_econ_env_RUS.pdf">Presentation 1
In Windows, using TEXTPAD, I have tried find/replace using regex (/Amalty-WS/[a-z,A-Z,0-9,_, ,]*\.pdf
) but can't figure out how to replace only the spaces.
You can use
(?:\G(?!^)|/Amalty-WS/)[^"\s]*\K\s(?=[^"]*")
Replace with _
.
See the regex demo.
Details:
(?:\G(?!^)|/Amalty-WS/)
- either the end of the previous successful match (\G(?!^)
) or /Amalty-WS/
string[^"\s]*
- zero or more chars other than "
and whitespace\K
- match reset operator that discards text matched so far\s
- a whitespace(?=[^"]*")
- followed with zero or more chars other than "
and then a "
.