regex –make option
The –make option is described by its author as “a remedy for headaches.” It outputs a regexp for one of several common patterns that are given as arguments, as listed in table.
List of ready regexps available in txt2regex
Argument | Description |
---|---|
date | This argument matches dates in mm/dd/yyyy format, from 00/00/0000 to 99/99/9999. |
date2 | This argument matches dates in mm/dd/yyyy format, from 00/00/1000 to 19/39/2999. |
date3 | This argument matches dates in mm/dd/yyyy format, from 00/00/1000 to 12/31/2999. |
hour | This argument matches time in hh:mm format, from 00:00 to 99:99. |
hour2 | This argument matches time in hh:mm format, from 00:00 to 29:59. |
hour3 | This argument matches time in hh:mm format, from 00:00 to 23:59. |
number | This argument matches any positive or negative integer. |
number2 | This argument matches any positive or negative integer with an optional floating-point value. |
number3 | This argument matches any positive or negative integer with optional commas and an optional floating-point value. |
For example, you can use this to get a ready regexp for any valid hour in military time, as shown in listing.
Listing. Getting a date regexp with txt2regex
$ txt2regex --make hour3
RegEx perl : ([01][0-9]|2[0123]):[012345][0-9]
RegEx php : ([01][0-9]|2[0123]):[012345][0-9]
RegEx postgres: ([01][0-9]|2[0123]):[012345][0-9]
RegEx python : ([01][0-9]|2[0123]):[012345][0-9]
RegEx sed : ([01][0-9]|2[0123]):[012345][0-9]
RegEx vim : ([01][0-9]|2[0123]):[012345][0-9]
$