0

(city = 'pune' AND country = 'india') OR (division = 'it') AND (resource = 'someresource' )

これを括弧に応じてグループに分けたいと思います。

グループ1-(city = 'pune' AND country = 'india')
グループ2-(division = 'it')
グループ3-(resource = 'someresource' )

誰かがJavaの例の正規表現を提供できますか?

4

2 に答える 2

1

これを試してください:(デモ: http: //regexr.com?33u8e

(\(.+?\))

コード例(PHP):

<?php
     $subject = "(city = 'pune' AND country = 'india') OR (division = 'it') AND (resource = 'someresource' )";
     $pattern = '/(\(.+?\))/';
     preg_match($pattern, $subject, $matches);
     print_r($matches);
?>

別のアプローチ:分割してみてください(ポジティブルックビハインドを使用)

(?<=\))\s

編集:最終的な答え(Javaで)

String[] parts = str.split("(?<=\\))\\s");
于 2013-02-27T08:27:26.913 に答える
0

どうぞ:\((.+?)\)

string mystring = "(city = 'pune' AND country = 'india') OR (division = 'it') AND (resource = 'someresource' )";
Match results = Regex.Match(mystring, @"\((.+?)\)",RegexOptions.IgnoreCase);

foreach (Group g in results.Groups)
{
    string token = g.Value;
}

ライブデモ

于 2013-02-27T08:34:52.810 に答える