POSIX Regular Expressions
POSIX stands for Portable Operating System Interface. It defines a set of standard operating system interfaces based on the UNIX OS.
In POSIX Basic Regex syntax, most characters are treated as literals, i.e., they match only themselves. But, there are some exceptions, which are called Metacharacters.
Metacharacters | Descriptions |
. | Matches any single character. For example, a.c matches "abc", but [a.c] matches only "a", ".", or "c". |
– | Used to define a range. For example, [a-c] will match characters a to c (both inclusive). |
[ ] | To match anything inside the square brackets. For example, [bc] will match b or c. |
^ | Matches a single character that is not contained within the brackets. For example, [^a] will match anything except a. |
$ | Matches the ending position of the string if it is the last character of the regular expression. |
* | To match the preceding character 0 or more times. For example, [abc]* matches "", "a", "b", "c", "ca", "cba", "abccb", and so on. |
{n} | To match the preceding chars n times. For example, [0-9]{3} will match any 3 digits numbers within a range of 0 - 9. E.g., 123, 234, 345, and so on. |
{n,m} | To match the preceding char at least n times and not more than m times. For example, [0-9]{3,5} will match at least 3 digits numbers and not more than 5 digits numbers. E.g., 123, 3456, 45668, etc. |
