您需要一个可选的非捕获组:
([^\(]*) #first group stores function name \( #starting parenthesis (?: # optional non-capturing group start \b([^\)\(\]\[\}\{]+)\b #second group saves parameters passed to function )? # optional non-capturing group end \) #closing parenthesis
见 正则表达式演示 。
该 (?:...)? 使整体 \b([^\)\(\]\[\}\{]+)\b 模式序列可选。
(?:...)?
\b([^\)\(\]\[\}\{]+)\b
请注意,您可以使用该模式
([^(]*) #first group stores function name \( #starting parenthesis (?: # optional non-capturing group start \b([^][(){}]+)\b #second group saves parameters passed to function )? # optional non-capturing group end \) #closing parenthesis