Regex group is matching quotes when I don't want it to -
i have regular expression:
"([^"\\]|\\.)*"|(\s+) 
but problem is, when have input "foo" , use matcher go through groups, first group finds "foo" when want foo. doing wrong?
edit:
i'm using java , fixed it
"((?:[^"\\]|\\.)*)"|(\s+) 
the first capturing group wasn't including * whole string. enclosed within capturing group , made inner existing 1 non capturing group.
edit: no... it's working in online regex debuggers not in program...
capture contents of double quoted literal pattern (branch 1) , if matched grab it.
also, consider unrolling pattern:
"([^"\\]*(?:\\.[^\\"]*)*)"|(\s+) in java:
string pat = "\"([^\"\\\\]*(?:\\\\.[^\\\\\"]*)*)\"|(\\s+)"; note patterns (a|b)* cause stack overflow issue in java, that's why unrolled version preferable.
Comments
Post a Comment