java - regular expression to cut text -
this question has answer here:
i want cut text
unit=1111,space=(trk,0),disp=(mod,delete,delete),dsn=uuu.aaaaa.bbbbb
result :
unit=1111 space=(trk,0) disp=(mod,delete,delete) dsn=uuu.aaaaa.bbbbb
i tried myself m noob regular expression, used (\s+)=(\s+)
cut not work correct.
someone me ?
here java code
import java.util.regex.matcher; import java.util.regex.pattern; final string regex = "(\\s+)=(\\s+)"; final string string = "unit=1111,space=(trk,0),disp=(mod,delete,delete),dsn=uuu.aaaaa.bbbbb" final pattern pattern = pattern.compile(regex); final matcher matcher = pattern.matcher(string); while (matcher.find()) { system.out.println("full match: " + matcher.group(0)); (int = 1; <= matcher.groupcount(); i++) { system.out.println("group " + + ": " + matcher.group(i)); } }
you can use negative lookahead regex splitting:
string[] arr = str.split(",(?![^()]*\\))");
this assuming (
, )
balanced , unescaped.
regex breakup:
,
: match literal comma(?![^()]*\\))
: negative lookahead assert comma not inside(...)
Comments
Post a Comment