Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

__findViewWithAttributeInTreeThatMatches should use search instead of match #330

Closed
jrafaaael opened this issue Oct 13, 2024 · 3 comments · Fixed by #331
Closed

__findViewWithAttributeInTreeThatMatches should use search instead of match #330

jrafaaael opened this issue Oct 13, 2024 · 3 comments · Fixed by #331

Comments

@jrafaaael
Copy link
Contributor

jrafaaael commented Oct 13, 2024

I'm trying something like client.findViewWithAttributeThatMatches(attr="text", regex=re.compile(fr"\babc\b")). however, if "abc" isn't at beggining of the text, the view doesn't match

Changing regex.match to regex.search fix the issue

if root and attr in root.map and regex.match(root.map[attr]):

It doesn't seem to break anything

@dtmilano
Copy link
Owner

Nice finding. Feel free to create a pull request.

@dtmilano
Copy link
Owner

Take this into account, you can always do it with match too:

>>> import re
>>> r = re.compile(fr"\babc\b")
>>> r.match("xxx abc yyy")
>>> r = re.compile(fr"^.*\babc\b.*$")
>>> r.match("xxx abc yyy")
<re.Match object; span=(0, 11), match='xxx abc yyy'>

@jrafaaael
Copy link
Contributor Author

@dtmilano
hey! sorry for late response, I was a bit bussy last week

^.*\babc\b.*$

this seems to work like a charm! however, word boundary /b only should too
let me PR and discuss further there!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants