Get a ready regex
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
|
<th scope="col" align="left">
Description
</th>
|
date
|
<td>
This argument matches dates in mm/dd/yyyy format, from 00/00/0000 to 99/99/9999.
</td>
|
date2
|
<td>
This argument matches dates in mm/dd/yyyy format, from 00/00/1000 to 19/39/2999.
</td>
|
date3
|
<td>
This argument matches dates in mm/dd/yyyy format, from 00/00/1000 to 12/31/2999.
</td>
|
hour
|
<td>
This argument matches time in hh:mm format, from 00:00 to 99:99.
</td>
|
hour2
|
<td>
This argument matches time in hh:mm format, from 00:00 to 29:59.
</td>
|
hour3
|
<td>
This argument matches time in hh:mm format, from 00:00 to 23:59.
</td>
|
number
|
<td>
This argument matches any positive or negative integer.
</td>
|
number2
|
<td>
This argument matches any positive or negative integer with an optional floating-point value.
</td>
|
number3
|
<td>
This argument matches any positive or negative integer with optional commas and an optional floating-point value.
</td>
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]
$