Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
Processing...

Test String

Code Generator

Generated Code

package main import ( "regexp" "fmt" ) func main() { var re = regexp.MustCompile(`\A(what[\W_]+is[\W_]+your[\W_]+name[\W_]*){10,}`) var str = `First off, sorry for not reviewing quickly. I put off doing so a bit when I first saw this, then ended up quite tired and went to sleep. This seems quite similar in intent to the existing rule "repeating words in {}". Are there cases where that rule and this rule will both match the same text? It looks like you found and fixed the first issue I had, which was the redundant detection name. And fixed the second issue (that post bodies start with an HTML tag). Just FYI: a \`<p>\` is not the only HTML tag which can start a post body, but it is, by far, the most common. ##### In the version as of the point you removed it from SD: you use \`(.+?)\` in the second regex. That seems over-broad. I'd be much more comfortable if there was a relatively/moderately short limit to the number of characters there. Perhaps a couple/few hundred characters? However, that's probably not all that critical. The code: \`\`\` repeats = regex.match(r"\A(\w+(?:\W+\w+){%i}\W*){10,}" % (len(period.groups(0)[0].split()) + 1), s) \`\`\` doesn't appear to do what you're intending. It doesn't end up looking for a repeating pattern, it just looks for a bunch of words, which would match nearly anything and return the last portion of the text. For example, on [this post](https://metasmoke.erwaysoftware.com/post/366947), the first regex does [this](https://regex101.com/r/tTnkxh/1), which then results in the second regex being \`\Awhat\W+is\W+your\W+(.+?)what\W+is\W+your\b\` and is doing [this](https://regex101.com/r/0oVnFf/1). That makes the final regex be \`\A(\w+(?:\W+\w+){2}\W*){10,}\`, which is doing [this on that text](https://regex101.com/r/RI5ePw/1). However, it's going to match anything. For example, using the text of this comment as the body text, it does [this]().` if len(re.FindStringIndex(str)) > 0 { fmt.Println(re.FindString(str),"found at index",re.FindStringIndex(str)[0]) } }

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 Golang, please visit: https://golang.org/pkg/regexp/