<< Go Back to Regex Toool
Regex Tool Help
Regex Tool is a web based application for testing your PHP regular expressions
with fast to use, yet powerful interface. Regex tool was developed especially
for PHP developers, who often work with regular expression, but without
readily available tools for testing them. Sometimes debugging regular
expressions can be slow, because it might be hard to tell, for example, what
the expression is actually matching.
For quick guide on how to use, just enter the subject that you wish to use in
the larger text area and the pattern to the top area and hit the "Match / Split
/ Replace" button and you will get the resulting matches. Below you will find
more detailed information about the Regex Tool and available features.
Regex engines
The Regex Tool has support for 2 different regex engines. PCRE and POSIX, both
of which are integrated into PHP. Since POSIX does not have support for any
kind of pattern modifiers, an NC (no case) version is also available, which
makes the regular expressions case insensitive (using PHP's eregi functions).
Note that while both of these are supported, some features are only available
on PCRE. These features are:
- Multiple matches: The POSIX functions do not have any function to
return all matches from the string. Thus, it is not possible to gather all
matches, and only the first returned by the ereg function will be displayed.
On PCRE, all matches are displayed.
- Subject highlighting: The POSIX functions do not return the position
of the match inside the string. Thus, due to complexity of regex, it is not
possible to locate it in the original subject making highlighting impsosible.
Subject highlighting
One of the main features of the Regex Tool is ability to highlight strings
from original subject. This makes it easy to determine, what exactly was
matched in the subject. To highlight the match, simply click on the number on
the position column of the match. This will draw a black background color
for the highlighted part in the subject and color the text white to make it
easily noticable. If the matched string is empty, then extra "#" will be
temporarily inserted in the location of the match.
Note that highlighting is not available when using POSIX regex engine. Also,
if the full subject is not displayed, then the subject will of course be only
highlighted up to the displayed part.
Session handling
While any data you send through the form takes priority, all the data is also
stored in a session. This is handy, because it allows you to easily transfer
the session from one browser to another (in case you need to) or give the url
to the session to someone else. The url to the session is available in the
bottom of the form.
Note that it is highly advisable to either lock the session or copy it before
giving it to others. If you do not copy it, you and someone else may be using
the same session, which will interfere with both of your working.
The following buttons are available in the session management:
- New Session: This button will completely wipe all data and create
a new session for you to work on. In practice, this button is the easiest way
to clean your subject and pattern quickly.
- Copy Session: This button will create a new identical session to the
current one, allowing you to give the url to previous one to someone else, or
allowing you to make copy from a locked session.
- Lock Session: Locking a session means that it can no longer be
modified once it's been locked. In locked session, all the modification forms
are removed and only the results are displayed. Locking is useful, when you
need to show someone else the session, but do not want anyone to make
modifications to it anymore.
- Generate Permanent Url: Generating a permanent url allows you to
create a url, which creates a session like you currently have. The advantage is
that this url will be always usable, even after the session itself has
expired. Do note that browsers have limits to the length of the url, and you
may not be able to use very long subject with this feature.
Note that all sessions will expire eventually, and if you leave your browser
open for too long, the session might expire while you are still using the
Regex Tool, which may cause you to lose your data. Note that pretty much all
data, except the subject is resubmitted on every page load. Thus, by using the
"Keep subject" option, expiration of session should cause you to lose data.
Subject editing
While there is nothing too special about editing the subject, there are,
however few special features that you can take advantage of.
- Keep subject: The subject is not kept in the textarea field once
you submit it by default. The purpose of this to simply make the page load
faster, when you don't need to load multiple copies of the same subject
(especially when working subjects that are several hundred KBs). If you check
this option, however, the subject will always be kept in the textarea field
too.
- Full subject: Full subject option forces the Regex Tool to print
out the entire subject in the subject field display. If this option is not
enabled, only the first 5kb of the subject is displayed. This makes handling
larger subjects easier, but sometimes you may still want to see the entire
subject. Note that parts which are not displayed can not be highlighted
either.
- Edit Subject: If you are not using the "Keep Subject" feature, you
can click on this button, and it will load the subject for you to edit in
the text area field.
- Copy Modified: If you click on the "Edit Subject" button, the subject
will be copied into the text area field exactly as you have submitted it.
However, if you are using "Parse whitespace" or "Parse HTML entities" option,
the actual used input will be modified. This button will copy the modified
subject to the subject field.
- Copy Replace: When you perform replacing, the result of replace
is displayed in separate div. However, if you press this button, the result
of replace will be copied into the textarea field.
You may also use the form to upload a file to use as a subject. If you use the
file upload, the subject is read from the file instead of the form. However,
after that you may edit the subject normally, as if you had entered it through
the form.
Options
There are also few addinational options in the options panel, that can help
you and provide extra features. Note that all the settings default to most
commonly used settings, so most of the times you don't really need to change
them at all.
- Show whitespace: This option enableds you to see the whitespace in
the matches, split array, subject and replace output. In otherwords, in all of
these, all whitespace characters are replaced with characters you can see. This
can be especially handy, when you are dealing with spesific line endings.
- Parse whitespace: When this option is enabled, \r, \n and \t are
replaced with appropriate whitespace characters. In addition \\ is replaced
with \ allowing you to escape the characters, if needed. This may be useful
when you need spesific line ending characters in subject, since it may be hard
to insert them through webform otherwise. This option may also be useful, if
you are copying pattern from PHP source, since it will interpret any double
backslashes (\\) as a single backslash (\).
- Parse HTML entities: When enabled, any HTML entities in input will
be interpreted as the characters they represent. Useful in only very rare cases
but may still be prove to be useful occasionally.
- Multiline patterns: After enabling this option, the pattern and
replace fields will be replaced with multiline textareas instead. Input fields
may not allow you to handle patterns with multiple lines, but this should prove
helpful in those cases.
Sometimes it may be hard to enter the exact lineending you wish in the form
input. The translation setting allows you to translate all the line endings
to what you want. Do note however that this is done prior to parsing whitespace,
which means that if you use this to remove whitespace, all that is left is the
whitespace you manually entered.
In addition to the other choices, you may also choose here the engine you
wish to use. The standard PHP regex engines are both available. The NC option
indicates that it is case insensitive matching (as POSIX does not have pattern
modifiers).
Additionally, there is a "Stress Test" setting, which allows you to run the
same pattern multiple times over the matches. This is useful, when you need to
test how effective some patterns are. The time it took to run the test is
available in the Information box.