patternMatch(pattern_string, input_string, ignore_case = False,
path_match = False)
→ int
This function is case-sensitive. Set ignore_case
to True for case-insensitive
pattern matching.
This function does not treat path separator characters specially. Set
path_match
to True for path-aware matching, where the multi-level
wildcard () is required to cover multiple path components.
Returns 1 if any patterns in the pattern string matches the input string, or 0 if no patterns match.
In order to match, a pattern must match the input string from beginning to end. Use wildcards (*) to match substrings, e.g.
>>> hou.patternMatch("bar", "foobarbaz") 0 >>> hou.patternMatch("*bar*", "foobarbaz") 1
pattern is a space-separated list of one or more patterns. This can cause unintuitive behavior of this function. For example:
>>> hou.patternMatch("foo bar", "foo bar") 0
…will return 0, because the first argument consists of two patterns, foo and bar, and neither of those patterns match foo bar (since the pattern must match from beginning to end).
Similarly,
>>> hou.patternMatch("foo bar", "foo") 1
…will return 1, because the string matches the first of the two arguments in the pattern (foo and bar).
>>> hou.patternMatch("/foo/*", "/foo/bar/blah", path_match = True) 0
…will return 0, because the wildcard only matches against the first path component (/bar), leaving the last path component (/blah) unmatched.
>>> hou.patternMatch("/foo/**", "/foo/bar/blah", path_match = True) 1
…will return 1, because the multi-level wildcard will matches against any number of path components.