Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Add re.findall to pick out re matches #805

Merged
merged 2 commits into from
Jul 30, 2024
Merged

Add re.findall to pick out re matches #805

merged 2 commits into from
Jul 30, 2024

Conversation

Jamstah
Copy link
Contributor

@Jamstah Jamstah commented Mar 9, 2024

Actually using re.finditer so we can apply a repl to the result. This allows users to pick out matches and reformat them in one step.

Fixes #804

@Jamstah
Copy link
Contributor Author

Jamstah commented Mar 9, 2024

Draft because it needs documentation.

@Jamstah Jamstah marked this pull request as ready for review March 10, 2024 17:59
docs/source/filters.rst Outdated Show resolved Hide resolved
Copy link
Owner

@thp thp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, I don't mind a re.findall(), but people might be tempted to use it to "parse" HTML (which is not possible using regex) when the CSS or XPath filters are more suited for the job.

If we make it clear in the docs when it isn't and when it is the right tool for the job, I'm happy to merge this :)

@Jamstah
Copy link
Contributor Author

Jamstah commented Mar 12, 2024

Yeah, I was thinking that but was too lazy to think of a good example :)

I've borrowed something from another test, and added some doc.

lib/urlwatch/filters.py Outdated Show resolved Hide resolved
lib/urlwatch/filters.py Outdated Show resolved Hide resolved
Copy link
Owner

@thp thp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comments.

Copy link
Owner

@thp thp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few comments, rest looks good. Thanks!

docs/source/filters.rst Outdated Show resolved Hide resolved
docs/source/filters.rst Outdated Show resolved Hide resolved
docs/source/filters.rst Outdated Show resolved Hide resolved
Comment on lines 538 to 539
XPATH expressions. HTML and XML cannot be parsed properly using regular
expressions. If the CSS selector or XPATH cannot provide the targeted
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could add a link to https://stackoverflow.com/a/1732454/1047040 on "cannot be parsed" for extra entertainment.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is a classic :)

Actually using re.finditer so we can apply a repl to the result. This
allows users to pick out matches and reformat them in one step.

Fixes thp#804

Signed-off-by: James Hewitt <[email protected]>
Copy link
Owner

@thp thp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@thp thp merged commit 654ce44 into thp:master Jul 30, 2024
0 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Feature request: Extension of regex filtering to extract data
2 participants