Since you are using the pattern with stringr methods that use ICU regex flavor, you may use a (?x)
free spacing (also called verbose, or ignore pattern whitespace) modifier where all unescaped whitespace is ignored when compiling the pattern, and there is a possibility to add comments after an unescaped #
on each line (so, all literal #
must be escaped).
Here is an example:
> library(stringr)
> regex_of_sites <- "(?x)side # Term 0
+ |southeast # Term 1
+ |north # Term 1
+ |computer # Term 2
+ |engineer
+ |first
+ |south
+ |pharm
+ |left
+ |southwest
+ |level
+ |second
+ |thirteenth"
> str_extract_all("first level", regex_of_sites)
[[1]]
[1] "first" "level"
The same modifier is supported by the PCRE patterns used in base R regex functions with perl=TRUE
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…