Sublime Forum

Regex capture groups in snippets

#1

Hello,

I’m trying to make a regex search and replace certain characters in fields in snippets. I currently have 3 groups 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]<![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}
]]>[/code]
Output:

[code]Æ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[/code]

Great, that works! The problem is that I want make all of those replacements work at once, so I tried adding this:

Replacement of all of those bad characters: ${1:/(æ)(ø)(å)(Æ)(Ø)(Å)]/(ae)(oe)(aa)(Ae)(Oe)(Aa)/g}

Which renders a useless output:

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?

0 Likes

#2

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

${1:/(?:(Å])?|\b)(?:(å])?|\b)(?:(Æ])?|\b)(?:(æ])?|\b)(?:(Ø])?|\b)(?:(ø])?|\b)/(?1:Aa)(?2:aa)(?3:Ae)(?4:ae)(?5:Oe)(?6:OE)/g}
0 Likes

#3

Take a look at how I do it with MagiclessQuotes: github.com/daryltucker/MagiclessQuotes/

0 Likes