[英]Pattern regex to find tab java
I have a statement as follows:我有如下声明:
String n =
\ul\insrsid14762702 Symptom}{\insrsid14762702\ul\insrsid14762702 Acid}{\insrsid14762702\ul\insrsid14762702 Nonacid}{\insrsid14762702\ul\insrsid14762702 All}{\insrsid14762702
Reg\tab 100%\tab 100%\tab 100%
Stg pain\tab 100%\tab 83%\tab 100%
F pain\tab 72%\tab 0%\tab 67%
I would like to see how many tabs there are but I always get zero returned for the size of the arrayList I thought I was adding to.我想看看有多少个选项卡,但对于我认为要添加到的 arrayList 的大小,我总是返回零。 My code:
我的代码:
Pattern patternTabs = Pattern.compile("\\tab",Pattern.DOTALL);
Matcher matcherTabs = patternTabs.matcher(n);
//Add the values between each tab.
ArrayList<String> colValue = new ArrayList<String>();
int count = 0;
while (matcherTabs.find())
colValue.add(matcher.group());
count++;
System.out.println("ffffffffffffff"+colValue.size());
I have tried \\\\\\\\tab
\\tab
tab
all other permutations with brackets but no joy.我试过
\\\\\\\\tab
\\tab
tab
所有其他带括号的排列,但没有任何乐趣。
A literal backslash in a regex requires 4 backslashes in the String literal (2 for regex, doubled again for java), so your regex should be:正则表达式中的文字反斜杠需要字符串文字中的4 个反斜杠(正则表达式为 2 个,java 再次加倍),因此您的正则表达式应该是:
"\\\\tab"
But your other "problem" is too much code;但是你的另一个“问题”是代码太多; just use
split()
:只需使用
split()
:
String[] colValues = n.split("\\\\tab");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.