Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
この文字列で Matcher を使用したい: #Function()(a)
単に選択するには: #Function()
私はこの正規表現を使用しています:
Pattern pat = Pattern.compile("\\#.*\\)"); Matcher match = pat.matcher(s);
そして、必要以上のものを選択しています: #Function()(a)。
')'が最初に出現したときに Matcher を停止するにはどうすればよいですか?
デフォルト.*では貪欲なので、すべてを合法的に保ちながら、可能な限り一致します。代わりにを使用することで不本意にすることができます。そう.*?すれば、すべてを合法に保ちながら、可能な限り一致しなくなります。
.*
.*?
.*使用する代わりに[^\\)]*
[^\\)]*
これを試して:
Pattern pat = Pattern.compile("\\#[^\\)]+\\)");