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<a href="wähle.html">Wähle</a>to<a href="w%C3%A4hle.html">Wähle</a>
Can anyone tell me how I do this?
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.
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 ä?
Hi,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 href="w%C3%A4hle.html".Is that correct?
Yes that's exactly right, any ideas?
Powergrep is a great program, I use it a lot, definitely worth the money!
I downloaded Powergrep (test version) and I've got your answer (I hope).
This works for me, put please use the preview function before altering anything.
I hope this helps you.
Worked perfectly. Thank you very much for your help, very kind
Sweet! That made me laugh out loud