brandon1024 / find

A find-in-page extension for Chrome and Firefox that supports regular expressions.
https://chrome.google.com/webstore/detail/find%2B-regex-find-in-page/fddffkdncgkkdjobemgbpojjeffmmofb
GNU General Public License v3.0
413 stars 54 forks source link

Whole Word #379

Open paulobuchsbaum opened 2 years ago

paulobuchsbaum commented 2 years ago

Great tool because, standard search tool in Chrome (the most used browser by far) sucks. It's just a very basic search.

So it would be immensely useful for almost all users if this tool (Find + Regex) had the whole word option (similar to Office and other tools)

I know that it would be possibile to reproduce it using regular expression:

     (?:^|[-\s\(){}[\]/\\|<>=])+(item)(?=$|[\s\-(){}[\]/\\|<>=])

Where one need to replace the item with the desired word.

I like this regex because it extends the word concept and considers (, ), {, }, [, ], |, \, /, <, >, = and – as word separators. This approach includes numbers (in many formats) within the whole word concept and and additionally fits many foreign languages.

However, using regex to simulate whole word is very clumsy.

brandon1024 commented 2 years ago

This extension only supports regular expressions that are supported by the Javascript language. Building a custom regex engine isn't exactly something I want to build and support in the long term.

mrienstra commented 1 year ago

@paulobuchsbaum, it sounds like you want something like VS Code's "Match Whole Word" find option, which essentially just wraps your search with \b (though it first checks to see if it's needed or not on each end), see microsoft/vscode src/vs/base/common/strings.ts#L182-L189.

VS Code also has EditorOption.wordSeparators for "[c]haracters that will be used as word separators when doing word related navigations or operations." (source):

`~!@#$%^&*()-=+[{]}\\|;:\'",.<>/?

... But I don't believe that's used for finding/searching, but rather for selecting / navigating / etc.


If I'm understanding you correctly, as to your suggestion:

Similar functionality could be added, I do find it convenient occasionally to use VS Code's "Match Whole Word" find option, though more often I just manually add \b as desired, since I usually leave "Use Regular Expression" on, and when I toggle other less-used options on ("Match Whole Word", "Match Case"), I sometimes forget that I've done so and waste time being confused as to why I can't find something.