Working on pattern language

This commit is contained in:
Hadley Wickham
2022-01-09 12:41:42 -06:00
parent e1375dfb18
commit 8ec221c922
2 changed files with 54 additions and 59 deletions

View File

@@ -617,6 +617,8 @@ Don't forget that you're in a programming language and you have other tools at y
Instead of creating one complex regular expression, it's often easier to write a series of simpler regexps.
If you get stuck trying to create a single regexp that solves your problem, take a step back and think if you could break the problem down into smaller pieces, solving each challenge before moving onto the next one.
A regular expression is a program that must be written in a single string, and has no debugger, no built-in documentation.
### Using multiple regular expressions
When you have complex logical conditions (e.g. match `a` or `b` but not `c` unless `d`) it's often easier to combine multiple `str_detect()` calls with logical operators instead of trying to create a single regular expression.
@@ -634,4 +636,3 @@ The results are identical, but I think the first approach is significantly easie
If your regular expression gets overly complicated, try breaking it up into smaller pieces, giving each piece a name, and then combining the pieces with logical operations.
### Repeated `str_replace()`