Home Download Buy Blog Forum Support

Regex capture groups in snippets

Regex capture groups in snippets

Postby jandahl on Wed Jan 02, 2013 2:09 pm

Hello,

I'm trying to make a regex search and replace certain characters in fields in [url="http://sublimetext.info/docs/en/extensibility/snippets.html"]snippets[/url]. I currently have 3 [url="http://www.regular-expressions.info/brackets.html"]groups[/url] that I try to put through. It's probably more of a regex problem than Sublime Text, but I hope someone else has had a similar issue.

Code example where each particular replacement works:
Code: Select all
<content><![CDATA[
${1:Name with dirty characters}

Replacement of æ: ${1/æ/ae/g}
Replacement of ø: ${1/ø/oe/g}
Replacement of å: ${1/å/aa/g}
Replacement of Æ: ${1/Æ/Ae/g}
Replacement of Ø: ${1/Ø/Oe/g}
Replacement of Å: ${1/Å/Aa/g}
]]></content>

Output:
Code: Select all
Æblegrød med Øllebrød og Ålesovs åbne øl nær Solrød

Replacement of æ: Æblegrød med Øllebrød og Ålesovs åbne øl naer Solrød
Replacement of ø: Æblegroed med Øllebroed og Ålesovs åbne oel nær Solroed
Replacement of å: Æblegrød med Øllebrød og Ålesovs aabne øl nær Solrød
Replacement of Æ: Aeblegrød med Øllebrød og Ålesovs åbne øl nær Solrød
Replacement of Ø: Æblegrød med Oellebrød og Ålesovs åbne øl nær Solrød
Replacement of Å: Æblegrød med Øllebrød og Aalesovs åbne øl nær Solrød


Great, that works! The problem is that I want make all of those replacements work at once, so I tried adding this:
Code: Select all
Replacement of all of those bad characters: ${1:/[(æ)(ø)(å)(Æ)(Ø)(Å)]/(ae)(oe)(aa)(Ae)(Oe)(Aa)/g}

Which renders a useless output:
Code: Select all
Replacement of all of those bad characters: Æblegrød med Øllebrød og Ålesovs åbne øl nær Solrød


Anybody able to discern what I am doing wrong?
jandahl
 
Posts: 2
Joined: Wed Nov 28, 2012 2:15 pm

Return to Technical Support

Who is online

Users browsing this forum: No registered users and 23 guests