-
Notifications
You must be signed in to change notification settings - Fork 1
Regex Almanac
Moti Barski edited this page Apr 10, 2025
·
1 revision
A high-use Regex collection for the RegexUtil class.
-
(?<=(one two)).*?(?=four)
Example: one two three four → three -
(?<=^).*?(?=$)
Returns the whole string between start and finish. -
(?<=one).*?(?=four)
Example: one two three four → two three
-
^.*(person|server).*$
Example:- This person is cool → This person is cool
- vanil stick → nothing
- server one → server one
-
^((?!.*(server|choco).*).)*$
Example:- vanil stick → vanil stick
- server one → nothing
-
\\s+[^\\s]+
Example: mister meeseeks → meeseeks
-
\\d+(\\.\\d+)?
Example: 20.05
[A-Za-z0-9.-]+\\.[A-Za-z]{2,6]
-
([0-9].){4}[0-9]*
Example: 10.10.10.126
-
0\\d-\\d{7}
Example:- 02-1234567
- Regex:
^0\\d-\\d{7}$
-
[0]\\d{9}
Phone starting with 0 followed by 9 digits.
-
\\b(\\w+)\\b(?=.*\\b\\1\\b)
Example: hadoken hadoken shoryuken → hadoken -
\\b([\\w\\s']+) \\1\\b
Example: hadoken hadoken shoryuken → hadoken hadoken
[-+]?[0-9]{1,13}
-
[A-Z][a-z]*\s[A-Z][a-z]*
Example: Heihachi Mishima
-
[-+]?[0-9]*[.,][0-9]*
Example: -30.77
-
[0-9]{1,4}/[0-9]{1,2}/[0-9]{1,2} [0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}
Example: 2023/09/29 14:30:45
-
[0-9]{1,2}:[0-9]{1,2}:[0-9]{1,2}→ 11:52:31 -
[0-9]{1,2}:[0-9]{1,2}→ 11:42
-
[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,6] -
^[a-zA-Z0-9._%+-]+@([a-zA-Z0-9.-]*element[a-zA-Z0-9.-]*)\.[a-zA-Z]{2,}$
Emails with "element" in them (good for bans). -
^*@gmail.[a-zA-Z]{2,}$
Emails from providers like Gmail (good for bans).
^.+$
-
+: Contains 1 or more of a character. -
*: Contains 0 or more of a character. -
?: Contains 0 or 1 of a character. -
(abc)+: Matches "abc" or "abcabcabc." -
[a-z]: Matches lowercase letters;[ab]matches "a" or "b." -
{5}: Quantifier; e.g.,ab{2}c→ abbc -
|: OR; e.g.,apple|bananamatches "apple" or "banana." -
.: Any character; e.g.,a.c→ "abc," "a1c," "acc." -
^: String start. -
$: String end.
-
(0x)?[0-9a-fA-F]+: Hexadecimal. -
\\b[01]+\\b: Binary. -
(?<=0.).*: Removes leading zero. -
M{0,3}(CM|CD|D?C{0,3})(XC|XL|L?X{0,3})(IX|IV|V?I{0,3}): Roman numerals. -
[0-9]{1,3}(,[0-9]{3})*\.[0-9]+: Numbers with thousand separators.
-
^\\w+
Example: one two three → one
-
\\w+$
Example: one two three four → four
-
[^\\d]+
Example: h3llo → h llo