# Rx

Generic regexps to build lenses

Author: Raphael Pinson rap.nosp@m.hink@gmai.nosp@m.l.com

Summary

Rx | Generic regexps to build lenses
License | This file is licensed under the LGPL v2+, like the rest of Augeas.
Spaces |
space | A mandatory space or tab
opt_space | An optional space or tab
cl | A continued line with a backslash
cl_or_space | A cl or a space
cl_or_opt_space | A cl or a opt_space
General strings |
space_in | A string which does not start or end with a space
no_spaces | A string with no spaces
word | An alphanumeric string
integer | One or more digits
relinteger | A relative integer
relinteger_noplus | A relative integer, without explicit plus sign
decimal | A decimal value (using ‘,’ or ‘.’
reldecimal | A relative decimal
byte |
hex | A hex value
octal | An octal value
fspath | A filesystem path
All but... |
neg1 | Anything but a space, a comma or a comment sign
IPs | Cf.
ipv4 |
ipv6 |
ip | An ipv4 or ipv6
hostname | A valid RFC 1123 hostname
device_name | A Linux device name like eth0 or i2c-0.
email_addr | To be refined
iso_8601 | ISO 8601 date time format

### License

This file is licensed under the LGPL v2+, like the rest of Augeas.

### Spaces

### space

> let space = /[ \t]+/

A mandatory space or tab

### opt_space

> let opt_space = /[ \t]*/

An optional space or tab

### cl

> let cl = /[ \t]*\\\\\n[ \t]*/

A continued line with a backslash

### cl_or_space

> let cl_or_space = cl | space

A cl or a space

### cl_or_opt_space

> let cl_or_opt_space = cl | opt_space

A cl or a opt_space

### General strings

### space_in

> let space_in = /[^ \r\t\n].*[^ \r\t\n]|[^ \t\n\r]/

A string which does not start or end with a space

### no_spaces

> let no_spaces = /[^ \t\r\n]+/

A string with no spaces

### word

> let word = /[A-Za-z0-9_.-]+/

An alphanumeric string

### integer

> let integer = /[0-9]+/

One or more digits

### relinteger

> let relinteger = /[-+]?[0-9]+/

A relative integer

### relinteger_noplus

> let relinteger_noplus = /[-]?[0-9]+/

A relative integer, without explicit plus sign

### decimal

> let decimal = /[0-9]+([.,][0-9]+)?/

A decimal value (using ‘,’ or ‘.’ as a separator)

### reldecimal

> let reldecimal = /[+-]?[0-9]+([.,][0-9]+)?/

A relative decimal

### byte

> let byte = /25[0-5]?|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]/

A byte (0 | 255)

### hex

> let hex = /0x[0-9a-fA-F]+/

A hex value

### octal

> let octal = /0[0-7]+/

An octal value

### fspath

> let fspath = /[^ \t\n]+/

A filesystem path

### All but...

### neg1

> let neg1 = /[^,# \n\t]+/

Anything but a space, a comma or a comment sign

### IPs

Cf. http://blog.mes-stats.fr/2008/10/09/regex-ipv4-et-ipv6/ (in fr)

### ipv4

> let ipv4 = let dot = "." in byte . dot . byte . dot . byte . dot . byte

### ipv6

> let ipv6 = /(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})/ | ( /([0-9A-Fa-f]{1,4}:){6}/ . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/ . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/ ) | ( /([0-9A-Fa-f]{1,4}:){0,5}:/ . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/ . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/ ) | ( /::([0-9A-Fa-f]{1,4}:){0,5}/ . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/ . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/ ) | ( /[0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}/ . /[0-9A-Fa-f]{1,4}/ ) | /(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){1,7}:)/

### ip

> let ip = ipv4 | ipv6

An ipv4 or ipv6

### hostname

> let hostname = /(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*( [A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])/

A valid RFC 1123 hostname

### device_name

> let device_name = /[a-zA-Z0-9_?.+:!-]+/

A Linux device name like eth0 or i2c-0. Might still be too restrictive

### email_addr

> let email_addr = /[A-Za-z0-9_+.-]+@[A-Za-z0-9_.-]+/

To be refined

### iso_8601

ISO 8601 date time format

> let space = /[ \t]+/

A mandatory space or tab

> let opt_space = /[ \t]*/

An optional space or tab

> let cl = /[ \t]*\\\\\n[ \t]*/

A continued line with a backslash

> let cl_or_space = cl | space

A cl or a space

> let cl_or_opt_space = cl | opt_space

A cl or a opt_space

> let space_in = /[^ \r\t\n].*[^ \r\t\n]|[^ \t\n\r]/

A string which does not start or end with a space

> let no_spaces = /[^ \t\r\n]+/

A string with no spaces

> let word = /[A-Za-z0-9_.-]+/

An alphanumeric string

> let integer = /[0-9]+/

One or more digits

> let relinteger = /[-+]?[0-9]+/

A relative integer

> let relinteger_noplus = /[-]?[0-9]+/

A relative integer, without explicit plus sign

> let decimal = /[0-9]+([.,][0-9]+)?/

A decimal value (using ‘,’ or ‘.’

> let reldecimal = /[+-]?[0-9]+([.,][0-9]+)?/

A relative decimal

> let byte = /25[0-5]?|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9]/

> let hex = /0x[0-9a-fA-F]+/

A hex value

> let octal = /0[0-7]+/

An octal value

> let fspath = /[^ \t\n]+/

A filesystem path

> let neg1 = /[^,# \n\t]+/

Anything but a space, a comma or a comment sign

> let ipv4 = let dot = "." in byte . dot . byte . dot . byte . dot . byte

> let ipv6 = /(([0-9A-Fa-f]{1,4}:){7}[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){6}:[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){5}:([0-9A-Fa-f]{1,4}:)?[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){4}:([0-9A-Fa-f]{1,4}:){0,2}[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){3}:([0-9A-Fa-f]{1,4}:){0,3}[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){2}:([0-9A-Fa-f]{1,4}:){0,4}[0-9A-Fa-f]{1,4})/ | ( /([0-9A-Fa-f]{1,4}:){6}/ . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/ . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/ ) | ( /([0-9A-Fa-f]{1,4}:){0,5}:/ . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/ . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/ ) | ( /::([0-9A-Fa-f]{1,4}:){0,5}/ . /((((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))\.){3}/ . /(((25[0-5])|(1[0-9]{2})|(2[0-4][0-9])|([0-9]{1,2})))/ ) | ( /[0-9A-Fa-f]{1,4}::([0-9A-Fa-f]{1,4}:){0,5}/ . /[0-9A-Fa-f]{1,4}/ ) | /(::([0-9A-Fa-f]{1,4}:){0,6}[0-9A-Fa-f]{1,4})/ | /(([0-9A-Fa-f]{1,4}:){1,7}:)/

> let ip = ipv4 | ipv6

An ipv4 or ipv6

> let hostname = /(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9\-]*[a-zA-Z0-9])\.)*( [A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9\-]*[A-Za-z0-9])/

A valid RFC 1123 hostname

> let device_name = /[a-zA-Z0-9_?.+:!-]+/

A Linux device name like eth0 or i2c-0.

> let email_addr = /[A-Za-z0-9_+.-]+@[A-Za-z0-9_.-]+/

To be refined
Close