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

filter regexp: '?' not working? #274

Open
mobileink opened this issue May 14, 2021 · 1 comment
Open

filter regexp: '?' not working? #274

mobileink opened this issue May 14, 2021 · 1 comment

Comments

@mobileink
Copy link

Hi,

I need to watch .*\.ml$ and .*\.mli$ files. I think regex `.*.ml.?$" ought to work, but it doesn't, so I need to add two filters. Should '?' work? (This is using the C API of libfswatch.)

Thanks

@direvus
Copy link

direvus commented Apr 7, 2022

This works for me:

fswatch -E -i '\.mli?$' -e '.*' .

Note the -E to switch into "extended" regexp mode.

A general tip for writing regexps: putting .* at the start or end of a pattern doesn't change anything, unless you are using a function that specifically anchors at the beginning or end of a string, or only matches against the entire string.

For example, in Python, re.match() only matches at the beginning of a string, but re.search() matches anywhere in the string. Most of the time unless you're told otherwise, a regexp will match anywhere in the string. In fswatch, it definitely matches anywhere in the string.

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

No branches or pull requests

2 participants