regex online

Input your words/sequences that should be contained or not, characters allowed or forbidden and test it in real time.using AND / OR / wildcard / sequence / word-boundary / flags / optional / non-capture / balanced Test your regular expressions online in real time for PHP/PCRE and Javascript. We'll look ahead/behind, positive or negative and make it work, set the flags and flavour(PHP or Js).

[*Fixed special characters group bug, you can include exclude chars]
regex online

Your Regex..

Regex:

Replace:

Match:

Replace using callback function:

Save to history

Preview

Clear and Start New


it needs to be a number

Edit regex
groups
*start here..


[Start] - Group

Please provide at least one valid value.
Please call a back-ref.
it needs to be a non-0 number
a set of chars needed
a sequence or word needed
a sequence or word needed



Please provide at least one valid value.
Please call a back-ref.
it needs to be a non-0 number
a set of chars needed
a sequence or word needed
a sequence or word needed



[End] - Group

Please provide at least one valid value.
Please call a back-ref.
it needs to be a non-0 number
a set of chars needed
a sequence or word needed
a sequence or word needed



Flavour

please select

Flags

Opt-match


Captured groups
Backreference

Named or indexed backreference called within the EXPRESSION..


  1. Captured groups can be named using the
Backref Section
?<block_1>

  2. Then called later in the expression using the
Group Type Section
\k<block_1>
(as backfererence), block_1 being your chosen name for the captured group
/(?<block_1>[0-9]+)(.)+(\k<block_1>)/

  3. You can call captured groups by their index
/([0-9]+)(.)+(\1)/
(as backfererence), 1 being the index for the first captured group.
* Capturing groups(if they are to be called as backreference) HAVE to be enclosed in round brackets ( group ).

Named or indexed backreference inside the REPLACE..


  1. If you need to call the whole match inside the replace you can use $& or $0:
Javascript:    var replace = 'some text $& some text';
PHP:    $replace = 'some text $0 some text';

  2. Index capturing groups can be called inside the replace($1 being the backreference for the first captured group):
Javascript:    var replace = 'some text $1';
PHP:    $replace = 'some text $1';

  3.* Only in JAVASCRIPT named capturing groups can be called inside the replace($<block_1> being the backreference for the named captured group):
var replace = 'some text $<block_1>';

  4. Named capturing groups can be called and used inside the callback function, you should have the function served by the server with your regex.

Variables within the EXPRESSION..


  1. If you need to call variables inside your regex:
var variable='sweet';
Javascript:    var pattern = new RegExp(`(apple )(${variable})( orange)`,'g');

*Note that you cannot replace the backtick( ` ) with any other type of quotes(simple ' or double ") or the expression will fail.

~

$variable='sweet';
PHP:    $pattern = '/(apple )('.$variable.')( orange)/g';

Variables inside the REPLACE..


  1. If you need to call variables inside the replace, you will concatenate as usual in your programming language:
var variable='sweet';
Javascript:    var replace = 'replace text '+variable+' more replace text';

~

$variable='sweet';
PHP:    $replace = 'replace text '.$variable.' more replace text';

Example

 Match the outerHTML of any html element(container type, not nesting) using backreference groups.

Flags


  i
Enables the case-insensitive mode, n and N are viewed as similar.

  m
Enables the multiline mode, ^ will match the begining of every new line(not just the begining of the string) and $ will match the end of every new line(not just the end of the string).

  s
Enables the white space dotal mode, should be used to match searchable text cross new lines.

  g
* Enables the full global search, used in Javascript to continue the search after the first match has been found.

Notions (.)+


  WILDCARD - ammounts for an unknown quantity of searchable text for which we can set a list of allowed characters, restrict certain characters or sequences/words and set a minimum and/or a maximum length.
  CAPTURED - groups represent parts of the searchable text that matched entirely or differents parts of the regular expression being ENCLOSED in ROUND BRACKETS (group).
  BACKREFERENCE - holds a reference to a captured group, a handle to that value and can be used later within the expression to balance groups or stipulate unicity or in the replace string and ultimately in the callback function.
  BALANCED - groups will match the N(number of occurrences) for group A and B within the searchable text and are generally used to match open and close brackets like "(" and ")" or to match html containers nesting or not. Balanced groups are not integrated in the same manner by all programming languages and more importantly at least in the case of nesting groups the expression will have to rescan within inner layers of all the matched, captured groups slowing the entire execution.
* The best aproach is to handle the balanced groups inside the callback function while deleting the outer layers of all captured groups and record their position/existence.

  NON-CAPTURED - groups need to be present within the searchable text in order to have a positive match for the regular expression however they will not be recorded nor present within the returned match.
* Non-captured groups are often uset to mark the boundaries or intermediary states of a regular expression in order to match the inner content of a subgroup or to ignore punctuation and any other unwanted text.

  WHITESPACE - Generally the types of whitespace found with regular expressions are the space (\ ), the new line (\n), the tab (\t) and the carriage return (\r). However this special character (\s) will match any of the previous whitespaces.
We use Cookies/Localstorage technologies to make sure you will have the best experience on our site. By clicking "Got it" or exiting this banner, you accept our use of cookies, only essential ones, these cookies are required for our website to function and cannot be disabled.