Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other regex replace multiple chars of different kind

  • This topic is empty.
Viewing 1 post (of 1 total)
  • Author
    Posts
  • #146356
    twincy
    Participant

    hi there.

    i need to replace all left { and right } curly braces as well as all percentage signs % to its respective html entity in a document.

    i’m using Sublime Text 2′s nice little star icon/button in Find and Replace to work with the regex and i came up with (\{)|(\})|(\%) to match those chars i need. might be better ways, but hey… they seem to match.

    how would the replacement string look like for this? i mean ONE expression, not with a programming language. basically it’s replacing what i find with group $1 with something and then the same for group $2 with something else – here in pseudo-code:

    (\{)|(\})|(\%) ==> $1 replace with &#xxx AND $2 replace with &#yyy AND... etc. 
    

    u follow?

    is it possible? does it make sense or should i take a nap?

    i can provide some target sample data if needed.

    some back story, if interested:

    these three characters can’t be placed as is inside an attributes value in HAML, like: :text => "blabliblu {20% lalla...}" etc. without being escaped.

    the percentage sign could theoretically be escaped with \% but the curly braces can not be escaped with \{ and \} respectively, at least not when i’m preprocessing the HAML with Livereload (win7). maybe it’s a Ruby thing? anyhow, i’m going for the html entity thingy.

    ah yeah, and don’t give me the TH̘Ë͖́̉ ͠P̯͍̭O̚​N̐Y̡ H̸̡̪̯ͨ͊̽̅̾̎Ȩ̬̩̾͛ͪ̈́̀́͘ ̶̧̨̱̹̭̯ͧ̾ͬC̷̙̲̝͖ͭ̏ͥͮ͟Oͮ͏̮̪̝͍M̲̖͊̒ͪͩͬ̚̚͜Ȇ̴̟̟͙̞ͩ͌͝S̨̥̫͎̭ͯ̿̔̀ͅ thingy, ok? u know what i mean…… ;)

    good evening, fellas.

Viewing 1 post (of 1 total)
  • The forum ‘Other’ is closed to new topics and replies.