3.2. Import the Regular Expression Library
Problem
To be able to use regular expressions in your application, you want to import the regular expression library or namespace into your source code.
Tip
The remainder of the source code snippets in this book assume that you have already done this, if needed.
Solution
C#
using System.Text.RegularExpressions;
VB.NET
Imports System.Text.RegularExpressions
Java
import java.util.regex.*;
Python
import re
Discussion
Some programming languages have regular expressions built-in. For these languages, you don’t need to do anything to enable regular expression support. Other languages provide regular expression functionality through a library that needs to be imported with an import statement in your source code. Some languages don’t have regex support at all. For those, you’ll have to compile and link in the regular expression support yourself.
C#
If you place the using
statement at the top of your C# source
file, you can reference the classes that provide regular expression
functionality directly, without having
to fully qualify them. For instance, you can write Regex()
instead of System.Text.RegularExpressions.Regex()
.
VB.NET
If you place the Imports
statement at the top of your VB.NET
source file, you can reference the classes that provide regular
expression functionality directly, without having to fully qualify
them. For instance, you can write Regex()
instead of System.Text.RegularExpressions.Regex()
.
Java
You have to import the java.util.regex
package into ...
Get Regular Expressions Cookbook 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.