Numerical Methods at work

Disclaimer:
Permission to use, copy, and distribute this software, and It’s documentation for any non-commercial purpose is hereby granted without fee, provided: THE SOFTWARE IS PROVIDED "AS-IS" AND WITHOUT WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR OTHERWISE, INCLUDING WITHOUT LIMITATION, ANY WARRANTY OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL Henrik Vestermark, BE LIABLE FOR ANY SPECIAL, INCIDENTAL, INDIRECT OR CONSEQUENTIAL DAMAGES OF ANY KIND, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER ADVISED OF THE POSSIBILITY OF DAMAGE, AND ON ANY THEORY OF LIABILITY, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.

Regular expression testing App

This app allows you to test regular expressions before using them, ensuring they provide the desired outcomes. Simply enter your regular expression in the input field, specify any modifiers, and input the text you want to test for matches. You can also enter a second regular expression to test simultaneously against the same text. Press the 'Match' button to execute, and the Matching Results section will list any matches found. This dual-testing feature allows for more thorough validation of your regular expressions.Version 1.9 includes optimization and analytics of regular expressions. Furtherdown under Additional resouces is the download section for three papers on regular expressions.

Regular Expression vs. 1.9 Type in your regular expression for testing: 
//
//
//
Enter your test string(s) for matching:
Matching or Optimizing result:



  • Result
  • Decomposing
  • Optimizing
  • Analysis
  • Help
  • Help Analysis

JavaScript Regular Expressions Guide

Modifiers

Modifier Description
i Perform case-insensitive matching
g Perform a global match (find all matches rather than stopping after the first match)
m Perform multiline matching

Brackets

Expression Description
[abc] Find any character between the brackets
[^abc] Find any character NOT between the brackets
[0-9] Find any digit between the brackets
[^0-9] Find any non-digit NOT between the brackets
(x|y) Find any of the alternatives specified

Groups

Group Type Description
(...) Matches the enclosed pattern and captures it (Capturing group).
(?:...) Matches the enclosed pattern but does not capture it (Non-capturing group).
(?=...) Lookahead assertion: Matches a group after the main expression without including it in the result.
(?!...) Negative lookahead assertion: Specifies a group that cannot match after the main expression if the result is to be successful.
(?<name>...) Matches the enclosed pattern and assigns it to a named group.
(?<=...) Lookbehind assertion: Matches a group before the main expression without including it in the result.
(?<!...) Negative lookbehind assertion: Specifies a group that cannot match before the main expression if the result is to be successful.

Quantifiers

Quantifier Description
n+ Matches any string that contains at least one n
n* Matches any string that contains zero or more occurrences of n
n? Matches any string that contains zero or one occurrence of n
n{X} Matches any string that contains a sequence of X n's
n{X,Y} Matches any string that contains a sequence of X to Y n's
n{X,} Matches any string that contains a sequence of at least X n's

Meta characters

Meta character Description
. Find a single character, except newline or line terminator
\w Find a word character
\W Find a non-word character
\d Find a digit
\D Find a non-digit character
\s Find a whitespace character
\S Find a non-whitespace character
\b Find a match at the beginning/end of a word
\B Find a match not at the beginning/end of a word
\0 Find a NULL character
\n Find a newline character
\f Find a form feed character
\r Find a carriage return character
\t Find a tab character
\v Find a vertical tab character
\xxx Find the character specified by an octal number xxx
\xdd Find the character specified by a hexadecimal number dd
\uxxxx Find the Unicode character specified by a hexadecimal number xxxx

Help Section: Description of Statistics

General Stats

matchCount:

The total number of matches found in the input string. Includes both full matches and any matches within groups.

executionTime:

The total time (in milliseconds) taken to execute the regex on the input string.Helps measure the performance of the regex.

inputCharactersProcessed:

The total number of input characters evaluated by the regex engine. A higher value indicates more work performed by the engine.

skippedInput:

The total number of characters in the input string that did not match the regex. Reflects areas of inefficiency or non-matching input.

Match Analysis

matchLengthDistribution:

A breakdown of matches grouped by their lengths. Shows how many matches fall into each length category. Example:
Match Length Distribution:
Length Count
0 2
3 4

zeroLengthMatchCount:

The number of zero-length matches found during execution. Useful for identifying potential inefficiencies or risks of infinite loops.

Node-Level Analysis

nodesVisited:

The total number of nodes in the Abstract Syntax Tree (AST) that were visited during execution. Reflects the complexity of the regex evaluation.

nodeTypeMatches:

A breakdown of how many successful matches occurred for each type of AST node.
Example:
Node Type Matches:
CHAR_CLASS 5
QUANTIFIER 2

nodeTypeFailures:

A breakdown of how many failed matches occurred for each type of AST node. Highlights areas of inefficiency where the regex engine failed to match.
Example:
Node Type Failures:
CHAR_CLASS 3
LITERAL 1

Backtracking Stats

backtrackCount:

The total number of backtracking steps performed during execution. A high value indicates potential inefficiencies in the regex, such as overly greedy quantifiers or excessive alternations.

backtrackDistance:

The total distance (in characters) moved backward during backtracking. A larger value suggests more significant inefficiencies in the regex structure.

maxBacktrackDepth:

The maximum depth of backtracking reached during execution. Reflects the most complex or nested level of backtracking encountered.
Usage Examples

Optimizing a Regex:

High values for backtrackCount or backtrackDistance suggest areas where the regex can be optimized.

nodeTypeFailures can indicate which nodes are failing frequently, allowing you to refactor specific parts of the regex.

Understanding Match Behavior:

matchLengthDistribution gives insights into the typical length of matches. A high zeroLengthMatchCount might indicate inefficiencies, especially with patterns like * or ?.

Analyzing Performance:

Compare inputCharactersProcessed to the input length to gauge how much unnecessary work the regex is performing. executionTime can be used to measure improvements after optimization.


Additional resources

Below is three additonal documents that I wrote about regular expression.

A tool for Optimizing regular expressions. Read more ...
A tool for decomposing regular expressions. Read more ...
Exploring Regular Expressions Through Practical Examples. Read more ...
ParseRegex.js User Manual. Read more ...
ParseRegex.js JavaScript code. Read more ...


Rate this page

Click on the stars below to rate this page

Low
a Star
a Star
a Star
a Star
a Star
High


Corrections:
23-Nov-2024 Vs 1.9 Added statictal information for executing regular expression
30-Sep-2024 Vs 1.8 Improved Optimizer
17-Sep-2024 Vs 1.7 Improved decomposition analysis and added optimization suggestion in a new button and tab called Optimize
25-Aug-2024 Vs 1.6 Added an optional second regular expression line to be tested simultaneously plus updated the help section
17-Aug-2024 Vs 1.5 Added more samples and introduce decomposing of regular expression
19-Nov-2020 Vs 1.4 Added multiline matching
17-Nov-2020 Vs 1.3 Fix a bug in reporting illegal regular expressions
23-Dec-2019 Vs 1.2 Fix a bug in retrieving the history of regular expressions
28-Oct-2019 Vs 1.1 Redesign the GUI Interface
25-Apr-2018 Vs 1 Initial release