I次の文字列を持っている:ブラケットから文字列を取り出す正規表現ですか?
「ドラゴンタトゥー(リズベス)を持つ少女」
と私は入力の最後に括弧にのみの文字列を取得する必要があります。
は、これまでのところ、私はこれに来た:
public static void main(String[] args) {
Pattern pattern =
Pattern.compile("\\({1}([a-zA-Z0-9]*)\\){1}");
Matcher matcher = pattern.matcher("The girl with the dragon tattoo (LISBETH)");
boolean found = false;
while (matcher.find()) {
System.out.println("I found the text " + matcher.group()
+ " starting at " + "index " + matcher.start()
+ " and ending at index " +
matcher.end());
found = true;
}
if (!found) {
System.out.println("No match found");
}
}
しかし、私が得る結果:(LISBETH)
。
これらの角かっこからどうやって離れますか?
ありがとうございます!
+1、等号の後ろに肯定的な表情ではありません。(?<= \\() '? –
@PetarMinchevもちろん正しいです。 – stema
一般的なヒント:あなたが必要としないときには、*不要な表現を複雑にするだけでなく、場合によっては間違っていることもあります。この場合、うまくいくでしょう。 "foo"、 "bar"、 "baz"を見つけるでしょう。 – Qtax