私の文字列 ( MY_STRING
) の内容は、次の形式である可能性があります。
bla bla...this is the id of product bla bla:#31 5 2 0000 12please verify bla bla ...
また
bla bla...this is the id of product bla bla: #31 5 2 0000 12, please verify bla bla...
また
bla bla...this is the id of product bla bla: #31 5 2 0000 12 please verify bla bla...
文字列から製品IDを抽出したい。上記の例の製品 ID は#31 5 2 0000 12です。
プロダクト ID の形式は、# で始まり、その後に乱数が続きます (長さに制限はありません)。数字間のスペースも任意です。
製品IDを抽出する現在のコードは次のとおりです。
Pattern pattern = Pattern.compile("^#\\d+(\\s+\\d+)*$");
Matcher matcher = pattern.matcher(MY_STRING);
if(phoneNrMatcher.find()){
System.out.println(matcher.group(0));
}
しかし、それはうまくいきません。おそらく正規表現?
ノート:
-私の例では、ID #31 5 2 0000 12の前後のコンテンツは任意です。
- 製品 ID 文字列は常に # で始まり、その後にスペースやその他の文字を含まない数字が続きます