F.5 Examples of using regular expressions
|
Specification |
Meaning |
String specified as a regular expression |
Example character string |
Match |
|---|---|---|---|---|
|
character-string |
Match lines containing the specified string. |
spring |
spring has come. |
Yes |
|
winter-summer-autumn-spring |
Yes |
|||
|
---- spring ----- |
Yes |
|||
|
^ character-string |
Match lines beginning with the specified string. |
^spring |
spring has come. |
Yes |
|
winter-summer-autumn-spring |
-- |
|||
|
-----spring----- |
-- |
|||
|
character-string $ |
Match lines ending with the specified string. |
spring$ |
spring has come. |
-- |
|
winter-summer-autumn-spring |
Yes |
|||
|
-----spring----- |
-- |
|||
|
^ character-string $ |
Match lines consisting of the specified string only. |
^spring$ |
spring has come. |
-- |
|
winter-summer-autumn-spring |
-- |
|||
|
spring |
Yes |
|||
|
|
-- |
|||
|
^$ |
Match null lines. |
^$ |
|
Yes |
|
spring |
-- |
|||
|
. (period) |
Match any character. |
in.e |
winter has come. |
Yes |
|
mother of invention |
Yes |
|||
|
life is in everything |
Yes |
|||
|
eight nine ten |
-- |
|||
|
increasing population |
-- |
|||
|
s..ing |
picnic in spring |
Yes |
||
|
skiing in winter |
Yes |
|||
|
[character-string] |
Signifies any of the characters specified in the string enclosed by [ and ]. |
[pr] |
spring has come. |
Yes |
|
today is Monday. |
-- |
|||
|
[character-character] |
Signifies a single character within the range, in the ascending order of character codes. |
[a-i] |
spring has come. |
Yes |
|
[character-character] |
Signifies a single character out of the range, in the ascending order of character codes. |
[^a-i] |
spring has come. |
Yes |
|
character * |
Match strings containing zero or more repetitions of the preceding characters. |
ro*m |
terminal |
Yes |
|
cd-rom |
Yes |
|||
|
living room |
Yes |
|||
|
h.*n |
This is a pen. |
Yes |
||
|
That is an apple. |
Yes |
|||
|
regular-expression | regular-expression |
Signifies either of the right and left regular expressions. |
[0-9]+|apple |
That is an apple. |
Yes |
|
spring in 2003 |
Yes |
|||
|
\ special-character |
Handles a special character as an ordinary character. |
o\.h |
<stdio.h> |
Yes |
|
another man |
-- |
|||
|
(regular-expression) |
Groups regular expressions. |
i(n.e|ng) |
winter has come. |
Yes |
|
interesting book |
Yes |
- Legend:
-
Bold type: Character string matching the specified regular expression.
Blank: Null line.
Yes: The example character string is a match.
--: The example character string is not a match.