Public class TestRegex {
Public static void main (String [] args) {
//string as follows:
String STR="x1, y1, 000, x2, y2, 100, the x3: y3, + 100, x4: y4, 050".
//expectations with regular expressions matching search, every time according to the second English comma as segmentation, return the result List
///"x1, y1, - 000", "x2, y2-100", "the x3: y3, + 100", "x4: y4, - 050"]
}
}
Thank you very much!
CodePudding user response:
Online find a contains regular expression, lixia out all contain ", "the subscript, then according to the subscript interception, don't understand why will have such a demand, a straight line between two points, the shortest like doing things around the two laps,CodePudding user response:
import Java. Util. Regex. Matcher.
Import the Java. Util. Regex. The Pattern;
Public class Test04 {
Public static void main (String args []) {
String line="x1, y1, 000, x2, y2, 100, the x3: y3, + 100, x4: y4, 050".
String pattern="[^,] + [^,] + (, | $)".
The Pattern running r=Pattern.com (Pattern);
The Matcher m=r.m atcher (line);
While (m. ind ()) {
System. The out. Println (m.g roup ());
}
}
}
CodePudding user response:
Using a variable num count, the initial 0, + 1, every encounter a comma when equal to 2 take a string output before, num is 0, then continue to take back