regular Expressions

.NET & JavaScript Regular Expression Tester

Target String:

Regular Expression:

case-insensitive     

Pattern: l.*?y

.NET
10 matches
Position   Match
36lazy
48Lazy
103lazy
120lazy
175lazy
196lazy
251lazy
263lazy
329lazy
346lazy
JavaScript
Position   Match

Regular expressions are used to identify specific patterns within text. They are useful for validating the format of email address, phone numbers, social security numbers, and other text with distinctive patterns. They are also useful for finding, replacing and extracting text.

Regular expressions allow patterns to be described in an abstract format. For example, the pattern "j\w*" will find all works starting with "j", followed by zero or more (*) words characters [a-zA-Z_0-9]. The pattern for a 5 digit number such as a zip code is "\d{5}" where "\d" represents any digits and {5} is the quantity.

The interpretion of regular expressions can differ depending upon the programming language or framework used. The tester above uses both Microsoft's .NET (server-side) and JavaScript (client-side).

Pattern Finds
lazy All instances of the word "lazy"
l.*?y All words starting with "l" and ending with "y". The "." represents any single character (except line breaks), the "*" means any quantity, and the "?" specifices non-greedy search (end at first match).
\b[tTq]\w*\b All strings starting with "t", "T", or "q"  (\b matches word boundary, square brackets [] defines a set of characters of which one must match, \w matches word characters: [a-zA-Z_0-9].
\b\w{3}\b All 3-letter words.
\d{3}-\d{4} All 7 digit phone numbers with a required dash after the third digit.
<.*?> All HTML tags. "." represents "any character," "*" is any quantity, ? is non-greedy search.
<(\w+>).+?</\1 Matching pairs of HTML tags using back references. The parenthesis () create a subexpression that can be referenced later in the expression. The \1 refers back to the first subexpression and requires matching text. For instance, if the subexpression matched on "h3" then the back reference \1 must also contain "h3."  
[\w!#$%*/?|\^\{\}'~\.]+@(\w+\.)*\w{2,3} All email addresses (this simplified expression will allow some invalid email formats).


Regular expressions are supported by most programming languages.  Useful links:

Wikipedia - regular expressions

Microsoft Beefs Up VBScript with Regular Expressions - old article but an excellent overview of regular expression syntax

Syntax Cheat Sheet - by Regular Expression Library

Regular Expression Library - lots of pre-written regular expressions.

ASP.NET Regular Expressions - Code for ASP.NET.

Regexper - Regular Expression visualizer

Regular Expressions HTML Color Names Color Picker ASCII Character Codes Unicode Character Codes