Regex - match anything between href=" and " that contains ä

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?

Hi,

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 :slight_smile:
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!

Hi,

I downloaded Powergrep (test version) and I’ve got your answer (I hope).

In Powergrep:

[LIST]
[]With your directory selected, go to the Action tab
[
]Select search and replace
[]Set Search type to Regular expression
[
]In Search enter: href="(.*?)"
[]In replace enter: href="$1"
[
]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
[/LIST]This works for me, put please use the preview function before altering anything.

I hope this helps you.

Danke sch%C3%B6%0An!! :slight_smile:

Worked perfectly. Thank you very much for your help, very kind :slight_smile:

Sweet! That made me laugh out loud :slight_smile: