about summary refs log tree commit diff
path: root/Doc/Zsh/mod_pcre.yo
blob: 58833823aa5b4713ccc3f6b868441fc966f936c2 (plain) (blame)
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
COMMENT(!MOD!zsh/pcre
Interface to the PCRE library.
!MOD!)
cindex(regular expressions, perl-compatible)
The tt(zsh/pcre) module makes some commands available as builtins:

startitem()
findex(pcre_compile)
item(tt(pcre_compile) [ tt(-aimx) ] var(PCRE))(
Compiles a perl-compatible regular expression.

Option tt(-a) will force the pattern to be anchored.
Option tt(-i) will compile a case-insensitive pattern.
Option tt(-m) will compile a multi-line pattern; that is,
tt(^) and tt($) will match newlines within the pattern.
Option tt(-x) will compile an extended pattern, wherein
whitespace and tt(#) comments are ignored.
)
findex(pcre_study)
item(tt(pcre_study))(
Studies the previously-compiled PCRE which may result in faster
matching.
)
findex(pcre_match)
item(tt(pcre_match) [ tt(-a) var(arr) ] var(string))(
Returns successfully if tt(string) matches the previously-compiled
PCRE.

If the expression captures substrings within parentheses,
tt(pcre_match) will set the array var($match) to those
substrings, unless the tt(-a) option is given, in which
case it will set the array var(arr).
)
enditem()

The tt(zsh/pcre) module makes available the following test condition:
startitem()
findex(pcre-match)
item(expr tt(-pcre-match) pcre)(
Matches a string against a perl-compatible regular expression.

For example,

[[ "$text" -pcre-match ^d+$ ]] && print text variable contains only "d's".
)
enditem()