regex - Java Unicode Regular Expression -
i have text this.
every person haveue280 sumue340 ambition
i want replace ue280, ue340 \ue280, \ue340 regular expression
is there solution
thanks in advance
something this?
string s = "every person haveue280 sumue340 ambition"; // put backslash in front of all "u" followed 4 hexadecimal digits s = s.replaceall("u\\p{xdigit}{4}", "\\\\$0");
which results in
every person have\ue280 sum\ue340 ambition
not sure you're after, perhaps it's this:
static string tounicode(string s) { matcher m = pattern.compile("u(\\p{xdigit}{4})").matcher(s); stringbuffer buf = new stringbuffer(); while(m.find()) m.appendreplacement(buf, "" + (char) integer.parseint(m.group(1), 16)); m.appendtail(buf); return buf.tostring(); }
(updated according axtavt nice alternative. making cw.)
Comments
Post a Comment