To be able to use regular expressions in your application, you want to import the regular expression library or namespace into your source code.
The remainder of the source code snippets in this book assume that you have already done this, if needed.
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.
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()
.
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()
.
You have to import the java.util.regex
package into your application to
be able to use Java’s built-in regular expression library.
If you want to use XRegExp to extend JavaScript’s
regular expression syntax, your web page will need to load the XRegExp
library. The easiest way to do that is to load xregexp-all-min.js
which includes all of
XRegExp’s functionality in minimized form. The XRegExp recipes in this book assume
you’re doing just that.
If you’re concerned about page loading times and you do not use
Unicode categories, blocks, and/or scripts, you can load the base
library xregexp-min.js
and load the addon libraries as needed. Load
unicode-base.js
to enable the ‹p{⋯}
› syntax for Unicode properties. You
can then load unicode-blocks.js
, unicode-categories.js
, and/or unicode-scripts.js
to make it possible to match
Unicode blocks, categories, and/or scripts with ‹p{⋯}
›.
If you are using Node.js to run JavaScript on a server,
then you’ll need to install XRegExp as an npm package. This can be
done by entering npm install
xregexp
on the command line. Once installed, your
server-side scripts can import the XRegExp library as shown in the
Solution section.