Skip to content

Commit 0ec504e

Browse files
Merge pull request #68 from TurekBot/patch-1
Add warning about "missing" parts of regex
2 parents e2d855b + 385b2f9 commit 0ec504e

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

README.md

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,16 @@ An error is displayed when used simultaneously.
292292
#### Regular expression matching
293293

294294
Regular expression matching can be enabled with the `--regexp` option (`-e` for short).
295-
When used, the assertion fails if the *extended regular expression* does not match `$output`.
295+
When used, the assertion fails if the *[extended regular expression]* does not match `$output`.
296+
297+
[extended regular expression]: https://en.wikibooks.org/wiki/Regular_Expressions/POSIX-Extended_Regular_Expressions
298+
299+
> [!IMPORTANT]
300+
> Bash [doesn't support](https://stackoverflow.com/a/48898886/5432315) certain parts of regular expressions you may be used to:
301+
> * `\d` `\D` `\s` `\S` `\w` `\W` — these can be replaced with POSIX character class equivalents `[[:digit:]]`, `[^[:digit:]]`, `[[:space:]]`, `[^[:space:]]`, `[_[:alnum:]]`, and `[^_[:alnum:]]`, respectively. (Notice the last case, where the `[:alnum:]` POSIX character class is augmented with underscore to be exactly equivalent to the Perl `\w` shorthand.)
302+
> * Non-greedy matching. You can sometimes replace `a.*?b` with something like `a[^ab]*b` to get a similar effect in practice, though the two are not exactly equivalent.
303+
> * Non-capturing parentheses `(?:...)`. In the trivial case, just use capturing parentheses `(...)` instead; though of course, if you use capture groups and/or backreferences, this will renumber your capture groups.
304+
> * Lookarounds like `(?<=before)` or `(?!after)`. (In fact anything with `(?` is a Perl extension.) There is no simple general workaround for these, though you can sometimes rephrase your problem into one where lookarounds can be avoided.
296305
297306
> _**Note**:
298307
> The anchors `^` and `$` bind to the beginning and the end of the entire output (not individual lines), respectively._

0 commit comments

Comments
 (0)