Let's see a few examples of regular expressions:
This regular expression would match any single word:
( +[a-zA-Z]+ +)
The initial + characters say we need 1 or more spaces.
The [a-zA-Z] set is all upper– and lower–case letters. The following plus sign says we need at least one letter and can have more.
The final + characters say we need to terminate the word with one or more spaces.
( +[a-zA-Z]+[?,\.]? +)
The [?,\.]? phrase means we might have a question mark, comma, or a period, but at most one. The period is escaped with a backslash because a bare period is a wildcard that will match anything.
It's easier to match an IP address. We know we'll have four three-digit numbers separated by periods.
The [0-9] phrase defines a number. The {1,3} phrase defines the count as being at least one digit and no more than three digits:
[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}
We can also define an IP address using the [[:digit:]] construct to define a number:
[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}\.[[:digit:]]{1,3}
We know that an IP address is in the range of four integers (each from 0 to 255), separated by dots (for example, 192.168.0.2).