for example String s = "<YLPY-F><XLPY-F><PY-3><RHP-6><SDY-1><LXBY-6><ZBL-P810>"; Pattern p = Pattern.compile("<(.*?)>"); Matcher m = p.matcher(s); while (m.find()) { System.out.println(m.group(1)); }
String s = "<<YLPY-F>bbb<aaa>><XLPY-F><PY-3><RHP-6><SDY-1><LXBY-6><ZBL-P810>"; Pattern p = Pattern.compile("(?<=[<>])([^<>].*?)(?=[<>])"); Matcher m = p.matcher(s); while (m.find()) { System.out.println(m.group(1)); } 是这个意思吗? <<YLPY-F>bbb<aaa>> 的YLPY-F和bbb和aaa都取出来?
String value = "<YLPY-F><XLPY-F><PY-3><RHP-6><SDY-1><LXBY-6><ZBL-P810>";
Pattern pattern = Pattern.compile("<(.*?)>");
Matcher matcher = pattern.matcher(value);
while(matcher.find()){
System.out.println(matcher.group(1));
}
public static void main(String[] args) {
String str = "<YLPY-F><XLPY-F><PY-3><RHP-6><SDY-1><LXBY-6><ZBL-P810>";
String arr[] = str.split("[><]+");
for(int i=1;i<arr.length;i++){
System.out.println(arr[i]);
}
}
Pattern pattern = Pattern.compile("(<(.*?)>)");
Matcher matcher = pattern.matcher(value);
while(matcher.find()){
System.out.println(matcher.group(2));
}
String s = "<YLPY-F><XLPY-F><PY-3><RHP-6><SDY-1><LXBY-6><ZBL-P810>";
Pattern p = Pattern.compile("<(.*?)>");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group(1));
}
Pattern p = Pattern.compile("(?<=[<>])([^<>].*?)(?=[<>])");
Matcher m = p.matcher(s);
while (m.find()) {
System.out.println(m.group(1));
}
是这个意思吗? <<YLPY-F>bbb<aaa>> 的YLPY-F和bbb和aaa都取出来?
String str = "<XLPY-F><PY-3><RHP-6><SDY-1><LXBY-6><ZBL-P810>";可能后面还有<LXBY-6><ZBL-P810>..不晓得有多少这种<XX>;
现在就是想把所有尖括号内的内容取出来
如果用group(1)只能取出第一个,如果再用group(2)去比对,那我不知到要比对多少次
string str = "<YLPY-F><XLPY-F><PY-3><RHP-6><SDY-1><LXBY-6><ZBL-P810>";
foreach(Match macth in Regex.Matches(str, @"<(.+?)>"))
{
if ( macth.Success)
{
Console.WriteLine("Found '{0}' at position {1} ,Group is {2} ",
macth.Value, macth.Index, macth.Groups[1]);
}
}