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
|
$XFree86$
LAST UPDATED: $Date$
This is a small regex library for fast matching tokens in text. It was built
to be used by xedit and it's syntax highlight code. It is not compliant with
IEEE Std 1003.2, but is expected to be used where very fast matching is
required, and exotic patterns will not be used.
To understand what kind of patterns this library is expected to be used with,
see the file <XRoot>xc/programs/xedit/lisp/modules/progmodes/c.lsp and some
samples in the file tests.txt, with comments for patterns that will not work,
or may give incorrect results.
The library is not built upon the standard regex library by Henry Spencer,
but is completely written from scratch, but it's syntax is heavily based on
that library, and the only reason for it to exist is that unfortunately
the standard version does not fit the requirements needed by xedit.
Anyways, I would like to thanks Henry for his regex library, it is a really
very useful tool.
Small description of understood tokens:
M A T C H I N G
------------------------------------------------------------------------
. Any character (won't match newline if compiled with RE_NEWLINE)
\w Any word letter (shortcut to [a-zA-Z0-9_]
\W Not a word letter (shortcut to [^a-zA-Z0-9_]
\d Decimal number
\D Not a decimal number
\s A space
\S Not a space
\l A lower case letter
\u An upper case letter
\c A control character, currently the range 1-32 (minus tab)
\C Not a control character
\o Octal number
\O Not an octal number
\x Hexadecimal number
\X Not an hexadecimal number
\< Beginning of a word (matches an empty string)
\> End of a word (matches an empty string)
^ Beginning of a line (matches an empty string)
$ End of a line (matches an empty string)
[...] Matches one of the characters inside the brackets
ranges are specified separating two characters with "-".
If the first character is "^", matches only if the
character is not in this range. To add a "]" make it
the first character, and to add a "-" make it the last.
\1 to \9 Backreference, matches the text that was matched by a group,
that is, text that was matched by the pattern inside
"(" and ")".
O P E R A T O R S
------------------------------------------------------------------------
() Any pattern inside works as a backreference, and is also
used to group patterns.
| Alternation, allows choosing different possibilities, like
character ranges, but allows patterns of different lengths.
R E P E T I T I O N
------------------------------------------------------------------------
<re>* <re> may occur any number of times, including zero
<re>+ <re> must occur at least once
<re>? <re> is optional
<re>{<e>} <re> must occur exactly <e> times
<re>{<n>,} <re> must occur at least <n> times
<re>{,<m>} <re> must not occur more than <m> times
<re>{<n>,<m>} <re> must occur at least <n> times, but no more than <m>
Note that "." is a special character, and when used with a repetition
operator it changes completely its meaning. For example, ".*" matches
anything up to the end of the input string (unless the pattern was compiled
with RE_NEWLINE, in that case it will match anything, but a newline).
Limitations:
o Only minimal matches supported. The engine has only one level "backtracking",
so, it also only does minimal matches to allow backreferences working
properly, and to avoid failing to match depending on the input.
o Only one level "grouping", for example, with the pattern:
(a(b)c)
If "abc" is anywhere in the input, it will be in "\1", but there will
not exist a "\2" for "b".
o Some "special repetitions" were not implemented, these are:
.{<e>}
.{<n>,}
.{,<m>}
.{<n>,<m>}
o Some patterns will never match, for example:
\w*\d
Since "\w*" already includes all possible matches of "\d", "\d" will
only be tested when "\w*" failed. There are no plans to make such
patterns work.
Some of these limitations may be worked on future versions of the library,
but this is not what the library is expected to do, and, adding support for
correct handling of these would probably make the library slower, what is
not the reason of it to exist in the first time.
If you need "true" regex than this library is not for you, but if all
you need is support for very quickly finding simple patterns, than this
library can be a very powerful tool, on some patterns it can run more
than 200 times faster than "true" regex implementations! And this is
the reason it was written.
Send comments and code to me (paulo@XFree86.Org) or to the XFree86
mailing/patch lists.
--
Paulo
|