Debugging regular expressions

Regular expressions can quickly become complicated and difficult to understand. Modifying a complex regular expression isn't a particularly simple undertaking.

While PowerShell indicates whether there's a syntax error in a regular expression, it can't do more than that. For example, in the following expression, PowerShell announces that there is a syntax error:

PS> 'abc' -match '*'
parsing "*" - Quantifier {x,y} following nothing.
At line:1 char:1
+ 'abc' -match '*'
+ ~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (:) [], ArgumentException
+ FullyQualifiedErrorId : System.ArgumentException

Fortunately, there are a number of websites that can visualize a regular expression and lend an understanding of how it works against a string.

Debuggex is one such site. This service can pick apart regular expressions, showing how each element applies to an example. Debuggex can be found at https://www.debuggex.com/.

Debuggex uses Java regular expressions, so some of the examples used in this chapter may not be compatible.

Online engines that are .NET-specific, but don't include visualization, are as follows:

Finally, the website (http://www.regular-expressions.info) is an important learning resource that provides detailed descriptions, examples, and references.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.13.113