3 Generic regexps to build lenses
5 Author: Raphael Pinson <raphink@gmail.com>
8 This file is licensed under the LGPL v2+, like the rest of Augeas.
16 A mandatory space or tab *)
19 (* Variable: opt_space
20 An optional space or tab *)
21 let opt_space = /[ \t]*/
24 A continued line with a backslash *)
25 let cl = /[ \t]*\\\\\n[ \t]*/
27 (* Variable: cl_or_space
28 A <cl> or a <space> *)
29 let cl_or_space = cl | space
31 (* Variable: cl_or_opt_space
32 A <cl> or a <opt_space> *)
33 let cl_or_opt_space = cl | opt_space
35 (* Group: General strings *)
38 A string which does not start or end with a space *)
39 let space_in = /[^ \r\t\n].*[^ \r\t\n]|[^ \t\n\r]/
41 (* Variable: no_spaces
42 A string with no spaces *)
43 let no_spaces = /[^ \t\r\n]+/
46 An alphanumeric string *)
47 let word = /[A-Za-z0-9_.-]+/
51 let integer = /[0-9]+/
53 (* Variable: relinteger
54 A relative <integer> *)
55 let relinteger = /[-+]?[0-9]+/
57 (* Variable: relinteger_noplus
58 A relative <integer>, without explicit plus sign *)
59 let relinteger_noplus = /[-]?[0-9]+/
62 A decimal value (using ',' or '.' as a separator) *)
63 let decimal = /[0-9]+([.,][0-9]+)?/
65 (* Variable: reldecimal
66 A relative <decimal> *)
67 let reldecimal = /[+-]?[0-9]+([.,][0-9]+)?/
71 let byte = /25[0-5]?|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]/
75 let hex = /0x[0-9a-fA-F]+/
83 let fspath = /[^ \t\n]+/
85 (* Group: All but... *)
87 Anything but a space, a comma or a comment sign *)
88 let neg1 = /[^,# \n\t]+/
92 * Cf. http://blog.mes-stats.fr/2008/10/09/regex-ipv4-et-ipv6/ (in fr)
98 byte . dot . byte . dot . byte . dot . byte
102 /(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})/
103 | /(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})/
104 | /(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})/
105 | /(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})/
106 | /(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})/
107 | /(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})/
108 | ( /([0-9A-Fa-f]{1,4}:){6}/
109 . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/
110 . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/
112 | ( /([0-9A-Fa-f]{1,4}:){0,5}:/
113 . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/
114 . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/
116 | ( /::([0-9A-Fa-f]{1,4}:){0,5}/
117 . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/
118 . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/
120 | ( /[0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}/
123 | /(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})/
124 | /(([0-9A-Fa-f]{1,4}:){1,7}:)/
128 An <ipv4> or <ipv6> *)
132 (* Variable: hostname
133 A valid RFC 1123 hostname *)
134 let hostname = /(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*(
135 [A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])/
138 * Variable: device_name
139 * A Linux device name like eth0 or i2c-0. Might still be too restrictive
142 let device_name = /[a-zA-Z0-9_?.+:!-]+/
145 * Variable: email_addr
148 let email_addr = /[A-Za-z0-9_+.-]+@[A-Za-z0-9_.-]+/
152 * ISO 8601 date time format
154 let year = /[0-9]{4}/
155 let relyear = /[-+]?/ . year
156 let monthday = /W?[0-9]{2}(-?[0-9]{1,2})?/
159 in let digits = /[0-9]{2}(:?[0-9]{2}(:?[0-9]{2})?)?/
160 in let precis = /[.,][0-9]+/
161 in let zone = "Z" | /[-+]?[0-9]{2}(:?[0-9]{2})?/
162 in sep . digits . precis? . zone?
163 let iso_8601 = year . ("-"? . monthday . time?)?
165 (* Variable: url_3986
166 A valid RFC 3986 url - See Appendix B *)
167 let url_3986 = /(([^:\/?#]+):)?(\/\/([^\/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?/