regexmatchspecial-charactersregex-negationoniguruma

Regex: Match word containing special characters


I am currently using a oniguruma regex to search for function like matches with the exception of some keywords. Ex, in the string "this is a test() and im() testing() thi[s]() this_[is]_a_fun(with,some,params)"

the regex should match: test, im, testing, thi[s] this_[is]_a_fun The current regex I'm using is

\s*([A-z0-9\w_]+).?(?=\()(\b(?<!if|while|for|return|else|elif|equals|or|xor|and|not|le|gre)) 

but this does not match thi[s] or any function containing brackets in the word.

I tried to update the regex to match these patterns with the regex

\s*([A-z0-9\w_|\[|\]]+).?(?=\()(\b(?<!if|while|for|return|else|elif|equals|or|xor|and|not|le|gre)) 

but to no avail.

Any help to match these kind of patterns would be greatly appreciated


Solution

  • Try this RegEx:

    ([\w+\[\]]+)(?=\([\w+,]*\))
    

    Demo
    Details: