-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathregexps.txt
139 lines (111 loc) · 6.68 KB
/
regexps.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
┏━━━━━━━━━━━━━┓
┃ REGEXPS ┃
┗━━━━━━━━━━━━━┛
USAGE ==> #Basic:
# - grep
# - expr
# - find
#Basic (without "boundaries"):
# - locate --regexp: no '^'
#Extended:
# - grep -E
# - find -regex
# - sed (except s/// y///)
# - awk
# - whatis -r
# - diff -I
# - GDB
#Extended (without "boundaries"):
# - Bash [[ =~ ]]
# - run-parts
# - locate --regex: no '^'
# - R
#Perl:
# - sed s/// y///: no \d \D
# - grep -P
# - agrep
#JavaScript
# - extra ones documented
# - no [[:CLASS:]]
# - no \< \>
# - no +-greediness
# - flags n|p|w -> m|s
# - no \A \Z but ^ $ behave like \A \Z unless m flag
ESCAPING ==> #Backslash escape depends on command.
Ö #Means a block, i.e. a single char, (...) or [...]
┌───────────┐
│ BASIC │
└───────────┘
Ö{x} #Ö present x times
Ö{x,y} #Ö present x to y times
Ö{x,} #Ö present at least x times
Ö* #Same as Ö{0,}
. #Any character, except newline
[ars] #
[a-p] #
[a-cjp-z] #Any of those characters
[[:CLASS:]] #Same, using a POSIX class
[^ars] #Any characters but those ones
[...&&...] #Intersection
#... can be another [...]
[...--...] #Subtraction
^ $ #Beginning|end of a line (newline-delimited)
() #Grouping ("capture group")
┌────────────────┐
│ BOUNDARIES │
└────────────────┘
\< \> #Beginning|end of a word (whitespace-delimited)
\b #\< or \>
\B #Inverse
\1, \2, etc. #Reference to 1st, 2nd, etc. capture group of the current or previous REGEXP
\& #Reference to full match
┌──────────────┐
│ EXTENDED │
└──────────────┘
Ö? #Same as Ö{0,1}
Ö+ #Same as Ö{1,}
Ö|Ö2 #Alternative
┌──────────┐
│ PERL │
└──────────┘
\w #[[:word:]]
\W #[^[:word:]]
\s #[[:space:]]
\S #[^[:space:]]
\d #[[:digit:]]
\D #[^[:digit:]]
\A \Z #Beginning|end (no delimiter)
Ö{...}?
Ö??
Ö+?
Ö*? #Not greedy: stops as soon as satisfied.
Ö{...}+
Ö?+
Ö++
Ö*+ #Greedy: continues as much as possible, even if might make regexp not match
(?:Ö) #Like (Ö), but not taking into account by \1, \2, etc.
Ö(?=Ö2) #Matches (only) Ö, providing it is followed by Ö2
Ö(?!Ö2) #Matches (only) Ö, providing it is not followed by Ö2
(?[FLAG...][-FLAG2...]:...) #Sets FLAG and unsets FLAG2, for ...
ADDITIONAL FLAGS ==> # . ^$
(default) # newline-wise newline-wise
n # not-newline-wise not-newline-wise
p # not-newline-wise not-newline-wise
w # newline-wise newline-wise
x #Allow comments: white-space and # and what follows (until newlines) are ignored, unless escaped
MODIFIERS ==> #Only in second part, e.g. of sed s///
\u \l #Next letter uppercase|lowercase
\U \L #Next letters uppercase|lowercase
\E #Stop current \U or \L
┌────────────────┐
│ JAVASCRIPT │
└────────────────┘
(?<GROUP>...) #Named capture group.
#Like (...) but with a name instead of an index (indexes are not incremented)
\k<GROUP> #Access capture groups (like \NUM does for normal (...) groups)
\p{PROP[=VAL]} #Like POSIX class but Unicode-friendly
#Matches any character than has the Unicode property PROP === VAL (def: true)
\P{PROP[=VAL]} #Inverse, i.e. PROP !==VAL
(?<=Ö2)Ö #Inverse of Ö(?=Ö2) and Ö(?!Ö2), i.e. preceded not followed
(?<!Ö2)Ö #Ö2 is processed from right to left, not left to right, including for greedy quantifiers and
#parenthesis groups numbers