Created
October 24, 2018 22:08
-
-
Save NHDaly/c59b6eac196a5aa50f43ca7a9e0e056a to your computer and use it in GitHub Desktop.
Regex: remove parens to turn a julia function call into a macro call
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
julia> m = "call( a( x()-1 ), 2+2 )" | |
>> "call( a( x()-1 ), 2+2 )" | |
julia> replace(m, r"a(\(((?>[^()]|(?1))*)\))" => s"@b \2") | |
>> "call( @b x()-1 , 2+2 )" | |
julia> # You can see the two capture groups here: the first around the parens (used for recursion), and the second inside the parens (for substitution). | |
julia> match(r"a(\(((?>[^()]|(?1))*)\))", m) | |
>> RegexMatch("a( x()-1 )", 1="( x()-1 )", 2=" x()-1 ") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment