python - How to escape rethinkdb regex pattern for r.match -
i want search r.match in rethinkdb using user input - whole user input should treated search pattern. i'm creating regex based on user input this:
pattern = u'.*(?i){0}.*'.format(user_input) but if user inputs '[' or ']' or other special character got errors rethink this:
error in regexp
.*(?i)\u0141[.*(portion[.*): missing ]: [.* in:
is there way escape regex rethinkdb? have tried use python re.escape fail when combining unicode errors one:
error in regexp
.*(?i)\\u0141.*(portion\\u0141): invalid escape sequence: \u0141
any suggestions?
use re.escape() function this:
escape(string)
return string non-alphanumerics backslashed; useful if want match arbitrary literal string may have regular expression metacharacters in it.
Comments
Post a Comment