zsh, to find all the strings that match a shell pattern, you can use this approach:
pattern='s?' # equivalent of regexp 's.'
sample_input='abcdsasd kmsa so
set -o extendedglob
Which here gives:
$ print -r -- $matches
sa sd sa so sd
That has several advantages over an approach using GNU
- it works whatever bytes or characters
$sample_input may contain. In particular NUL and NL and bytes not forming part of valid characters (which would still be matched by
- it doesn't have to rely on a GNUism
- zsh patterns are significantly more expressive than standard regular expressions.
There are a few PCRE operators that don't have an equivalent in zsh wildcards (such as look around ones). If you wanted to use those, you could use zsh's builtin
pcre_match command. The manual (see
info zsh pcre_match) has an example that does just that: extract matches into an array.