Reader small image

You're reading from  Mastering PowerShell Scripting - Fourth Edition

Product typeBook
Published inJun 2021
PublisherPackt
ISBN-139781800206540
Edition4th Edition
Right arrow
Author (1)
Chris Dent
Chris Dent
author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent

Right arrow

Grouping

A group in a regular expression serves several different possible purposes:

  • To denote repetition (of more than a single character)
  • To restrict alternation to a part of the regular expression
  • To capture values

Repeating groups

Groups may be repeated using any of the quantifiers. The regular expression that tentatively identifies an IP address can be improved using a repeated group. The starting point for this expression is as follows:

[0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ 

In this expression, the [0-9]+ term followed by a literal . character is repeated three times. Therefore, the expression can become as follows:

([0-9]+\.){3}[0-9]+ 

The expression itself is not specific, it will match much more than an IP address, but is also now more concise. This example will be explored further later in this chapter.

If * is used as the quantifier for the group, it becomes optional. If faced with a set of version numbers ranging...

lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Mastering PowerShell Scripting - Fourth Edition
Published in: Jun 2021Publisher: PacktISBN-13: 9781800206540

Author (1)

author image
Chris Dent

Chris Dent is an automation specialist with deep expertise in the PowerShell language. Chris is often found answering questions about PowerShell in both the UK and virtual PowerShell user groups. Chris has been developing in PowerShell since 2007 and has released several modules over the years.
Read more about Chris Dent