7.6. Matching ranges or sets using []

To match certain specific characters or ranges of characters use []. You can separate the different characters that you want to match inside the brackets with commas; this is not mandatory (some systems do moan if you don’t use commas on complex expressions) but it does make the pattern more readable.

To specify a range of characters use the dash (-). This specifies a set or range where the range starts on the left-hand side of the dash and finishes on the right-hand side of the dash.

You should always use the [] when you want to home in on a string match. Suppose we wanted to match any single number, we could use:

[0123456789] 

However, there is an easier method by using the dash (-):

[0-9] 

or any lower ...

Get Linux and Unix Shell Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.