171 @param wildcardPattern string containing the wildcard pattern (string) |
171 @param wildcardPattern string containing the wildcard pattern (string) |
172 @return string containing a regular expression (string) |
172 @return string containing a regular expression (string) |
173 """ |
173 """ |
174 pattern = wildcardPattern |
174 pattern = wildcardPattern |
175 |
175 |
176 pattern = re.sub(r"\*+", "*", pattern) # remove multiple wildcards |
176 pattern = re.sub(r"\*+", "*", pattern) # remove multiple wildcards |
177 pattern = re.sub(r"\^\|$", "^", pattern) # remove anchors following separator placeholder |
177 pattern = re.sub(r"\^\|$", "^", pattern) # remove anchors following separator |
178 pattern = re.sub(r"^(\*)", "", pattern) # remove leading wildcards |
178 # placeholder |
179 pattern = re.sub(r"(\*)$", "", pattern) # remove trailing wildcards |
179 pattern = re.sub(r"^(\*)", "", pattern) # remove leading wildcards |
180 pattern = re.sub(r"(\W)", "", pattern) # escape special symbols |
180 pattern = re.sub(r"(\*)$", "", pattern) # remove trailing wildcards |
|
181 pattern = re.sub(r"(\W)", r"\\\1", pattern) # escape special symbols |
181 pattern = re.sub(r"^\\\|\\\|", |
182 pattern = re.sub(r"^\\\|\\\|", |
182 r"^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?", pattern) # process extended anchor at expression start |
183 r"^[\w\-]+:\/+(?!\/)(?:[^\/]+\.)?", pattern) # process extended anchor at |
|
184 # expression start |
183 pattern = re.sub(r"\\\^", |
185 pattern = re.sub(r"\\\^", |
184 r"(?:[^\w\d\-.%]|$)", pattern) # process separator placeholders |
186 r"(?:[^\w\d\-.%]|$)", pattern) # process separator placeholders |
185 pattern = re.sub(r"^\\\|", "^", pattern) # process anchor at expression start |
187 pattern = re.sub(r"^\\\|", "^", pattern) # process anchor at expression start |
186 pattern = re.sub(r"\\\|$", "$", pattern) # process anchor at expression end |
188 pattern = re.sub(r"\\\|$", "$", pattern) # process anchor at expression end |
187 pattern = re.sub(r"\\\*", ".*", pattern) # replace wildcards by .* |
189 pattern = re.sub(r"\\\*", ".*", pattern) # replace wildcards by .* |
188 |
190 |
189 return pattern |
191 return pattern |
190 |
192 |
191 def setPattern(self, pattern, isRegExp): |
193 def setPattern(self, pattern, isRegExp): |
192 """ |
194 """ |