Created
May 19, 2015 09:23
-
-
Save hell0again/8730ca8f230a49881aec to your computer and use it in GitHub Desktop.
perl5.10以降で可能な入れ子を扱う正規表現
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
my $str = "a + (b * (3 / (c + 5)))"; | |
$str =~ /\(((?:[^()]++|(?R))*)\)/; | |
# /\( \)/; # 括弧にマッチ | |
# ( ) # 後方参照 | |
# (?:[^()]++|(?R))* # 括弧以外のバックトラックなしの貪欲マッチ または全体のパターンにマッチ(再帰) | |
print $1; ## "b * (3 / (c + 5))" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment