Regular Expressions 101

Save & Share

Flavor

  • PCRE2 (PHP >=7.3)
  • PCRE (PHP <7.3)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java 8
  • .NET 7.0 (C#)
  • Rust
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests

Tools

Sponsors
There are currently no sponsors. Become a sponsor today!
An explanation of your regex will be automatically generated as you type.
Detailed match information will be displayed here automatically.
  • All Tokens
  • Common Tokens
  • General Tokens
  • Anchors
  • Meta Sequences
  • Quantifiers
  • Group Constructs
  • Character Classes
  • Flags/Modifiers
  • Substitution
  • A single character of: a, b or c
    [abc]
  • A character except: a, b or c
    [^abc]
  • A character in the range: a-z
    [a-z]
  • A character not in the range: a-z
    [^a-z]
  • A character in the range: a-z or A-Z
    [a-zA-Z]
  • Any single character
    .
  • Alternate - match either a or b
    a|b
  • Any whitespace character
    \s
  • Any non-whitespace character
    \S
  • Any digit
    \d
  • Any non-digit
    \D
  • Any word character
    \w
  • Any non-word character
    \W
  • Non-capturing group
    (?:...)
  • Capturing group
    (...)
  • Zero or one of a
    a?
  • Zero or more of a
    a*
  • One or more of a
    a+
  • Exactly 3 of a
    a{3}
  • 3 or more of a
    a{3,}
  • Between 3 and 6 of a
    a{3,6}
  • Start of string
    ^
  • End of string
    $
  • A word boundary
    \b
  • Non-word boundary
    \B

Regular Expression
No Match

/
/
g

Test String

Code Generator

Generated Code

const regex = /((?:SFR)\ ?\d+|(?:[oO][rR])\ ?\d+|(?:[iI][pP][hH][oO][nN][eE])\ ?\d+|[\dA-Z]{12}|\d{2,})/g; // Alternative syntax using RegExp constructor // const regex = new RegExp('((?:SFR)\\ ?\\d+|(?:[oO][rR])\\ ?\\d+|(?:[iI][pP][hH][oO][nN][eE])\\ ?\\d+|[\\dA-Z]{12}|\\d{2,})', 'g') const str = `iOS device iOS device iOS device iOS device iOS device iOS device iOS device iOS device 1 347 4804 SFR113 189 4429 4657 4666 4790 8 Or4177 Or4195 Sfr5 OR4314 01068 1140 21 228 229 253 40 421 4462 4509 4650 4670 4696 4705 4747 4748 4751 4754 4785 4818 55 880 93 OR 1613 OR4329 OR4437 OR4440 Or4180 Or4183 Or4186 Or4187 Or4188 Or4190 Or4191 Or4199 Or4204 Or4208 Or4311 Or716 Or888 Sfr2-2 iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone 264 iPhone 335 F4LLKCCRFNDD F78LD2SFFFHM 0707 1055 1122 1138 1142 122 155 183 191 2 207 242 29 296 417 4427 4431 4496 4503 4507 4523 4524 4525 4526 4529 4532 4542 4543 457 4645 4649 4651 4653 4659 4660 4661 4667 4675 4680 4685 4690 4700 4702 4703 4706 4708 4709 4712 4716 4717 4718 4719 4745 4750 4752 4756 4757 4758 4761 4772 4780 4783 4784 4786 4795 4806 4807 4812 4814 4816 6 688 69 8 812 OR 1842 OR4309 OR4315 OR4328 OR4595 OR4635 Or333i Or4182 Or4198 Or4646 Sfr vtc Sfr3-3 Unknown-Host iPhone iPhone iPhone 1234 iPhone 261 iPhone 307 iPhone 1101 1257 128 226 254 279 4292 4430 4460 4463 4497 4499 4519 4522 4527 4533 4534 4537 4539 4553 4643 4647 4648 4652 4655 4658 4665 4671 4673 4674 4675 4677 4677 4683 4686 4689 4699 4753 4759 4763 4765 4767 4768 4769 4770 4773 4774 4775 4776 4777 4778 4779 4781 4782 4785 4785 4789 4791 4793 4794 4794 4796 4799 4801 4802 4803 4805 4808 4809 4810 4813 4815 4817 4819 4820 4821 7362 763 90 OR3871 OR3893 OR4100 OR4145 OR4220 OR4257 OR4261 OR4312 OR4357 OR4385 OR4399 OR4446 OR4447 OR4589 OR4618 OR4622 Or 4412 Or1262 Or1338 Or3927 Or4278 SFR1239 iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone iPhone #24 Or3600 0000 1010 1013 1102 1170 120 1203 1220 1233 131 14 162 1980 202 206 280 318 326 4465 4484 4495 4498 4500 4511 4531 4532 4535 4538 4541 4654 4687 4690 4691 4698 473 4739 4746 4755 4793 4800 4811 578 833 834 859 OR 1263 OR 1309 OR 1358 OR 1402 OR 1403 OR 1424 OR 1553 OR1754 OR1843 OR1862 OR2061`; // Reset `lastIndex` if this regex is defined globally // regex.lastIndex = 0; let m; while ((m = regex.exec(str)) !== null) { // This is necessary to avoid infinite loops with zero-width matches if (m.index === regex.lastIndex) { regex.lastIndex++; } // The result can be accessed through the `m`-variable. m.forEach((match, groupIndex) => { console.log(`Found match, group ${groupIndex}: ${match}`); }); }

Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions