Regular Expressions 101

Save & Share

  • Regex Version: ver. 1
  • Update Regex
    ctrl+⇧+s
  • Save new Regex
    ctrl+s
  • Add to Community Library

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 single character of: a, b, c or d
    [[ab][cd]]
  • 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]
  • Character class intersection
    [\w&&[^\d]]
  • 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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "\\w{0,10}((?i)(access.{0,1}key)|(access.{0,1}token)|(access.{0,1}id)|(secret.{0,1}key)|(secret.{0,1}token)|(api.{0,1}key)|(api.{0,1}secret)|(sign.{0,1}in)|(credential[A-Za-z0-9_\\-]{0,22})|ak|sk|akid|skid|auth|authentication|certificate|cookie|session|passwd|password|private|token|salt|secretid|accesskeyid|access_key_id|上线|发布|部署|令牌|凭证|口令|密码|密钥|登录|登陆|私钥|秘钥|认证|证书|帐号|账号|账密|配置|鉴权|验证|数据库|用户名|访问码|账号管理)\\s*[=:]\\s*\\\"[A-Za-z0-9_\\-]{6,33}\\\"\n"; final String string = "accesskey: \"123456pwd\"\n" + "accessKey: \"123456pwd\"\n" + "AccessKey: \"123456pwd\"\n" + "access key: \"123456pwd\"\n" + "access_key: \"123456pwd\"\n" + "secretkey: \"123456pwd\"\n" + "secretKey: \"123456pwd\"\n" + "SecretKey: \"123456pwd\"\n" + "secret key: \"123456pwd\"\n" + "secret_key: \"123456pwd\"\n" + "ak: \"123456pwd\"\n" + "sk: \"123456pwd\"\n" + "CredentialAzureAccessKey: \"123456pwd\"\n" + "CredentialKeyAli: \"123456pwd\"\n" + "CredentialKeyKingsoft: \"123456pwd\"\n" + "CredentialKeyTencent: \"123456pwd\"\n" + "CredentialSecretAli: \"123456pwd\"\n" + "CredentialSecretKingsoft: \"123456pwd\"\n" + "CredentialSecretTencent: \"123456pwd\"\n" + "CredentialUcloudPrivateKey: \"123456pwd\"\n" + "CredentialUcloudPublicKey: \"123456pwd\"\n" + "CredentialXingyuAccessKey: \"123456pwd\"\n" + "CredentialXingyuAccessSecret: \"123456pwd\"\n" + "Dockerfile: \"123456pwd\"\n" + "AkamaiAccessToken: \"123456pwd\"\n" + "AkamaiClientSecret: \"123456pwd\"\n" + "AkamaiClientToken: \"123456pwd\"\n" + "AwsSecretId: \"123456pwd\"\n" + "AwsSecretKey: \"123456pwd\"\n" + "AzureSubscriptionId: \"123456pwd\"\n" + "CredentialAzureAccessKey: \"123456pwd\"\n" + "CredentialKeyAli: \"123456pwd\"\n" + "CredentialKeyKingsoft: \"123456pwd\"\n" + "CredentialKeyTencent: \"123456pwd\"\n" + "CredentialSecretAli: \"123456pwd\"\n" + "CredentialSecretKingsoft: \"123456pwd\"\n" + "CredentialSecretTencent: \"123456pwd\"\n" + "CredentialUcloudPrivateKey: \"123456pwd\"\n" + "CredentialUcloudPublicKey: \"123456pwd\"\n" + "CredentialXingyuAccessKey: \"123456pwd\"\n" + "CredentialXingyuAccessSecret: \"123456pwd\"\n\n" + "1. Access Key 相关:: \"123456pwd\"\n" + "- Access Key: \"123456pwd\"\n" + "- AccessKey: \"123456pwd\"\n" + "- Access_Key: \"123456pwd\"\n" + "- AccessKeyID: \"123456pwd\"\n" + "- AccessKeyId: \"123456pwd\"\n" + "- Access_Key_ID: \"123456pwd\"\n" + "- AK: \"123456pwd\"\n" + "- AKID: \"123456pwd\"\n\n" + "2. Secret Key 相关:: \"123456pwd\"\n" + "- Secret Key: \"123456pwd\"\n" + "- SecretKey: \"123456pwd\"\n" + "- Secret_Key: \"123456pwd\"\n" + "- SecretAccessKey: \"123456pwd\"\n" + "- Secret_Access_Key: \"123456pwd\"\n" + "- SK: \"123456pwd\"\n" + "- Secret: \"123456pwd\"\n\n" + "3. Access Token 相关:: \"123456pwd\"\n" + "- Access Token: \"123456pwd\"\n" + "- AccessToken: \"123456pwd\"\n" + "- Token: \"123456pwd\"\n" + "- AuthToken: \"123456pwd\"\n" + "- Bearer Token: \"123456pwd\"\n" + "- Refresh Token: \"123456pwd\"\n\n" + "1. 账号相关:: \"123456pwd\"\n" + "- Username: \"123456pwd\"\n" + "- User: \"123456pwd\"\n" + "- Account: \"123456pwd\"\n" + "- Login: \"123456pwd\"\n" + "- Email: \"123456pwd\"\n" + "- UserID: \"123456pwd\"\n" + "- 用户名: \"123456pwd\"\n" + "- 账户: \"123456pwd\"\n\n" + "2. 密码相关:: \"123456pwd\"\n" + "- Password: \"123456pwd\"\n" + "- Pass: \"123456pwd\"\n" + "- Pwd: \"123456pwd\"\n" + "- 密码: \"123456pwd\"\n" + "- 口令: \"123456pwd\"\n" + "- 访问码: \"123456pwd\"\n\n" + "3. 登录相关:: \"123456pwd\"\n" + "- Signin: \"123456pwd\"\n" + "- Sign in: \"123456pwd\"\n" + "- Sign-in: \"123456pwd\"\n" + "- 登录: \"123456pwd\"\n" + "- 登陆: \"123456pwd\"\n" + "- 登入: \"123456pwd\"\n\n" + "4. 认证相关:: \"123456pwd\"\n" + "- Authentication: \"123456pwd\"\n" + "- Auth: \"123456pwd\"\n" + "- 认证: \"123456pwd\"\n" + "- 鉴权: \"123456pwd\"\n" + "- 验证: \"123456pwd\"\n\n" + "5. 凭证相关:: \"123456pwd\"\n" + "- Credential: \"123456pwd\"\n" + "- Credentials: \"123456pwd\"\n" + "- 凭证: \"123456pwd\"\n" + "- 证书: \"123456pwd\"\n" + "- 令牌: \"123456pwd\"\n"; final Pattern pattern = Pattern.compile(regex); final Matcher matcher = pattern.matcher(string); while (matcher.find()) { System.out.println("Full match: " + matcher.group(0)); for (int i = 1; i <= matcher.groupCount(); i++) { System.out.println("Group " + i + ": " + matcher.group(i)); } } } }

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 Java, please visit: https://docs.oracle.com/javase/7/docs/api/java/util/regex/Pattern.html