swift - NSRegularExpression regex replace Greek Unicode text -


i have html string i'm displaying in uiwebview. there's greek text, unicode range u+0370–u+03ff, i'd display in different font, enclosing in span. can search \p{script=greek}:

let regex = nsregularexpression(pattern: "(\\p{script=greek})", options:nil, error: nil) let newstring = regex!.stringbyreplacingmatchesinstring(entrytext, options: nil, range: nsmakerange(0, count(entrytext)), withtemplate: "<span class=\"gr\">$1</span>") 

but replaces each character. couldn't figure out how specify range \x… or \u.

the regular expression quantifier + means "match 1 or more of preceding element", , can used in case: (\\p{script=greek}+). greedy, means cause single match include many characters can, in case consecutive greek characters.


Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -