Regular expression in rreplace to remove parenthesis and all text contained within

I am attempting to use the rreplace function to remove text in the title contained in parenthesis, including the parenthesis. On regex101.com if I use the regex expression \s*\(.*?\) it finds the space before, both parenthesis and all the text contained within. When I try to use this in rreplace it removes all of the text in the title. The code is contained in a foreach loop as follows:

$set(%_loop_value%,$rreplace($get(%_loop_value%),\\s*\(.*?\),))

The documentation for picard indicates I need to escape $ , ( ) \ which I think I have done.

Can someone help me determine the correct syntax?

The problem is that you have escaped the ( but not the \ preceeding it. Try (untested code):

$set(%_loop_value%,$rreplace($get(%_loop_value%),\\s*\\\(.*?\\\),))

Bob may be right - an alternative possibility is that you need to enclose the part of the regex that you want to replace in brackets i.e. (\s*\(.*\))

You are right. I was not escaping all of the special characters and therefore $rreplace failed. I ran a test this afternoon in a blank script as follows and it works.

$set(title,$rreplace(%title%,\\s?\\\(.*?\\\)\\s?,))

Thank you for the input.

1 Like