boognish — 2012-11-30T03:01:15-05:00 — #1
I'm trying to do a regex find replace on a load of links that contain foreign characters such as ä and replacing them with their encoded version %C3%A4.
For example. I would want to replace
Can anyone tell me how I do this?
pullo — 2012-11-30T06:22:42-05:00 — #2
What are you using to do this?
Dreamweaver? A scripting language like Ruby?
Something like this maybe:
l = '<a href="wähle.html">Wähle</a>'
h = l.match(/href=".*?"/).to_s.gsub(/ä/, "ae")
l = l.sub(/href=".*?"/, h)
Bit ugly, but it does the job.
boognish — 2012-11-30T12:45:13-05:00 — #3
Thanks for your reply! I'm using a program called powergrep which can search regex statements and replace with what I want. So in my original example in the replace field I put '%C3%A4', but what regex can I use in the search field to match anything between href=" and " that contains ä?
pullo — 2012-11-30T14:00:02-05:00 — #4
I was just about to download Powergrep to try it out, then I saw it cost 120€. Oops
So, let me understand: You have a folder full of html files and want to use Powergrep to search through all of these files, line for line, and replace any occurrences of foreign characters within a href attribute with their encoded version. I.e.
href="wähle.html" would become
Is that correct?
boognish — 2012-11-30T15:27:49-05:00 — #5
Yes that's exactly right, any ideas?
Powergrep is a great program, I use it a lot, definitely worth the money!
pullo — 2012-11-30T16:00:42-05:00 — #6
I downloaded Powergrep (test version) and I've got your answer (I hope).
- With your directory selected, go to the Action tab
- Select search and replace
- Set Search type to Regular expression
- In Search enter:
- In replace enter:
- Set a tick by "Extra processing. Perform a search and replace on the replacement text or collect text"
- In extra processing search type "ä"
- In extra processing replace type "%C3%A4"
- Rinse and repeat
This works for me, put please use the preview function before altering anything.
I hope this helps you.
boognish — 2012-11-30T16:25:58-05:00 — #7
Worked perfectly. Thank you very much for your help, very kind
pullo — 2012-11-30T16:27:46-05:00 — #8
Sweet! That made me laugh out loud