RakkoTools

Regular Expression Tester

Online PHP/JavaScript/Python Regular Expression Tester

Add to favorite
Choose type
/ " / "

What this tool can

Regular Expression:

Regular Expression, Regex or Regexp, is a sequence of meta-characters that defines a text search pattern.
In this tool, a Regex starts with the meta-character '/' and ends with '/'.


Regex modifiers:

Also called flags, they change the behavior of the whole Regex.
For example, to match both 'hello' and 'Hello', instead of the Regex '/hello|Hello/', you can use '/hello/i'.
The modifier 'i' stands for case-insensitive.


Special regex characters:

^Matches from the beginning of the input. If the multi-line flag is added, matches from the beginning of each line in the input.
For example, /^Apple/ does not match 'An Apple a day...', but matches 'Apple never falls...'.
$Matches till the end of the input. If the multi-line flag is added, matches till the end of each line in the input.
For example, /eat$/ does not match 'In the eatery', but matches 'Let's eat'.
.(The decimal point) matches any single character except the newline character, by default. For example, /.n/ matches 'an' and 'on' in 'nay, an apple is on the tree', but not 'nay'. If the s ('dotAll') flag is set to true, it also matches newline characters.
[xyz]Character set. This pattern type matches any one of the characters in the brackets, including escape sequences. Special characters like the dot(.) and asterisk (*) are not special inside a character set, so they don't need to be escaped. You can specify a range of characters by using a hyphen, as the following examples illustrate. The pattern [a-d], which performs the same match as [abcd], matches the 'b' in 'brisket' and the 'c' in 'city'. The patterns /[a-z.]+/ and /[\w.]+/ match the entire string 'test.i.ng'.
*Matches the preceding expression 0 or more times. Equivalent to {0,}.
For example, /bo*/ matches 'boooo' in 'A ghost booooed' and 'b' in 'A bird warbled' but nothing in 'A goat grunted'.
+Matches the preceding expression 1 or more times. Equivalent to {1,}. For example, /a+/ matches the 'a' in 'candy' and all the a's in 'caaaaaaandy', but nothing in 'cndy'.
?Matches the preceding expression 0 or 1 time. Equivalent to {0,1}. For example, /e?le?/ matches the 'el' in 'angel' and the 'le' in 'angle' and also the 'l' in 'oslo'. If used immediately after any of the quantifiers *, +, ?, or {}, makes the quantifier non-greedy (matching the fewest possible characters), as opposed to the default, which is greedy (matching as many characters as possible). For example, applying /\d+/ to '123abc' matches '123'. But applying /\d+?/ to that same string matches only the '1'. Also used in lookahead assertions, as described in the x(?=y) and x(?!y) entries of this table.
{n}Matches exactly n occurrences of the preceding expression. N must be a positive integer.
For example, /a{2}/ doesn't match the 'a' in 'candy,' but it does match all of the a's in 'caandy,' and the first two a's in 'caaandy.'
{m,n}Where n and m are positive integers and n <= m. Matches at least n and at most m occurrences of the preceding expression. When m is omitted, it's treated as ∞.For example, /a{1,3}/ matches nothing in 'cndy', the 'a' in 'candy,' the first two a's in 'caandy,' and the first three a's in 'caaaaaaandy'. Notice that when matching 'caaaaaaandy', the match is 'aaa', even though the original string had more a's in it.
a-zMatches a character from a to z
A-ZMatches a character from A to Z
0-9Matches a character from 0 to 9

Useful for

  • Search for pattern in a text source.
  • Check if the text source follows the correct pattern.
  • Divide the text source based on well-defined patterns.

Common regexes:

Matches password/^[a-z0-9_-]{6,18}$/
Matches Hex value/^#?([a-f0-9]{6}|[a-f0-9]{3})$/
Matches Slug/^[a-z0-9-]+$/
Matches Email/^([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})$/
Matches URL/^(https?:\/\/)?([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?$/
Matches HTML tag/^<([a-z]+)([^<]+)*(?:>(.*)<\/\1>|\s+\/>)$/
Matches Youtube Video ID/https?:\/\/(?:youtu\.be\/|(?:[a-z]{2,3}\.)?youtube\.com\/watch(?:\?|#\!)v=)([\w-]{11}).*/gi
Matches file extension/^(.*\.(?!(htm|html|class|js)$))?[^.]*$/i

related tools