![](/img/trans.png)
[英]Convert a number from Base B1 to Base B2 without using any intermediate base
[英]how do I use regex to match expressions such as b1, b2, … thru b15, but no further?
我在運行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}$
提前謝謝了。
試試這個正則表達式:
\bb(?:1[0-5]|[1-9])\b
在Java中,你需要逃避\\
與其他\\
說明:
\\b
匹配單詞邊界 b
匹配字母b
(?:1[0-5]|\\d)
-匹配1,后跟0-5
范圍內的數字,或匹配1-9
一位數字 \\b
匹配單詞邊界 謝謝。 但這沒有用; 我擺弄着它,無法上班。 以下是詳細信息,但可以使用:
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"))) {
// valid
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.