Contents
What does RegEx exec return?
exec() The exec() method executes a search for a match in a specified string. Returns a result array, or null . JavaScript RegExp objects are stateful when they have the global or sticky flags set (e.g. /foo/g or /foo/y ).
Can you use RegEx with LS?
Bash, and thus ls , does not support regular expressions here. What it supports is filename expressions (Globbing), a form of wildcards. Regular expressions are a lot more powerful than that. Find is recursive by default, but ls is not.
How to use regex with find command in Linux?
The -regex find expression matches the whole name, including the relative path from the current directory. For find . this always starts with ./, then any directories. Also, these are emacs regular expressions, which have other escaping rules than the usual egrep regular expressions.
How to use regex inside exec with regular expression?
I want to be able to “exec” based on parts of the argument, like: You can’t use capture groups from the regexp in the command to execute. If you use find -regex to restrict matches, you’ll have to do some extra matching in the command. You can do that by invoking a shell and using its own pattern matching constructs.
How to switch from regex to egrep in find?
You can switch to egrep expressions by -regextype posix-egrep: (Note that everything said here is for GNU find, I don’t know anything about the BSD one which is also the default on Mac.) Judging from other answers, it seems this might be find’s fault.
How to use regex to restrict matches in a command?
If you use find -regex to restrict matches, you’ll have to do some extra matching in the command. You can do that by invoking a shell and using its own pattern matching constructs. For example, if foo and bar are constant strings and regex1 can’t match bar: Invoking a shell has a little overhead.