我在运行MacOs Mojave的Mac上使用Java和Eclipse。这似乎很容易,但我已经在上面花了4-5个小时。需要识别以下字符串:b1, b2, b3, ... b14, b15。
我尝试过"^b1[012345]{1}$ | ^b[1-9]?$和其他:(^b1[012345]{1}$) | (^b[1-9]{1}$)“
^b(1 | 2| 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | | 13 | 14 | 15){1}$甚至是^b( '1' | '2' | '3' | '4' | '5' | '6' | '7'... | '15'){1}$
在此之前,非常感谢您。
发布于 2019-02-01 13:52:01
试试这个正则表达式:
\bb(?:1[0-5]|[1-9])\b在Java语言中,您需要用另一个\来转义\
说明:
\b -匹配单词boundaryb -匹配字母b(?:1[0-5]|\d) -匹配1后跟范围内的数字或者匹配1-9\b中的单个数字0-5 -匹配单词边界发布于 2019-02-05 05:58:57
谢谢。但它不起作用;我摆弄它,不能开始工作。下面是详细信息,但它是有效的:
String first = pageText.substring(0, 1);
String rest = pageText.substring(1, pageText.length());
String pattern = "[^0-9]";
Matcher matcher = Pattern.compile(pattern).matcher(rest);
while (matcher.find()) {
JOptionPane.showMessageDialog(null,
"<html>Only b followed by a number between 1 and “
+ “15 in the page number field",
"Page Number Is Not Recognizable",
JOptionPane.ERROR_MESSAGE);
return;
}
int intRest = Integer.parseInt(rest); // string to integer
if ((intRest > 0 && intRest < 16) && (first.equals("b"))) {
// validhttps://stackoverflow.com/questions/54473576
复制相似问题