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

Re: Regex capture groups in snippets

Postby fredrikpaues on Tue Mar 17, 2015 8:00 pm

You are probably not interested in this anymore. But here goes nothing. This suggestions owes credit to viewtopic.php?f=2&t=5550#p24913.

Code: Select all
${1:/(?:([Å])?|\b)(?:([å])?|\b)(?:([Æ])?|\b)(?:([æ])?|\b)(?:([Ø])?|\b)(?:([ø])?|\b)/(?1:Aa)(?2:aa)(?3:Ae)(?4:ae)(?5:Oe)(?6:OE)/g}
fredrikpaues
 
Posts: 3
Joined: Thu Mar 12, 2015 8:57 pm

Re: Regex capture groups in snippets

Postby daryltucker on Mon Mar 23, 2015 4:47 pm

Take a look at how I do it with MagiclessQuotes: https://github.com/daryltucker/MagiclessQuotes/
daryltucker
 
Posts: 3
Joined: Mon Mar 23, 2015 4:33 pm


Return to Technical Support

Who is online

Users browsing this forum: No registered users and 16 guests