Regular Expressions 101

Save & Share

  • Regex Version: ver. 2
  • 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 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

import java.util.regex.Matcher; import java.util.regex.Pattern; public class Example { public static void main(String[] args) { final String regex = "```[\\S\\s]*?```"; final String string = "## 使用指南 (Usage)\n\n" + "**下载使用**\n" + "```js\n" + "git clone https://github.com/BiYuqi/webpack-seed.git\n\n" + "cd webpack-seed\n\n" + "npm install\n" + "```\n\n" + "**本地开发(dev)**\n" + "```js\n" + "npm run dev\n" + "```\n\n" + "**打包(build)**\n\n" + "* 默认情况下,该配置方案假设你的应用是被部署在一个域名的根路径上例如 https://www.my-app.com/\n" + "* 如果应用被部署在一个子路径上,你就需要用这个选项指定这个子路径\n" + "* 例如,如果你的应用被部署在 https://www.my-app.com/my-app/\n" + "* 则设置 webpack的output.publicPath 为 /my-app/\n" + "* 本项目由于需要临时部署在git-pages预览 所以改配置临时改为/webpack-seed/\n" + "* 普通打包(大部分) npm run build 默认 '/'\n" + "* 该命令具体请看package.json scripts命令配置\n" + "* [配置详情](https://github.com/BiYuqi/webpack-seed/blob/master/webpack.seed.common.js#L13)\n" + "* [scripts命令配置](https://github.com/BiYuqi/webpack-seed/blob/master/package.json#L8)\n\n" + "```js\n" + "// 普通打包(大部分) npm run build publicPath默认 '/'\n" + "npm run build\n\n" + "// 打包时 npm run build:git 该命令会打包的路径会自动带上github项目地址/webpack-seed/\n" + "//(当发布环境不是服务器根路径,都可以采用该方案,只需更改路径名称即可,本项目二级路径为webpack-seed)\n" + "npm run build:git\n\n" + "```\n" + "**依赖分析**\n" + "```js\n" + "// 利用webpack-bundle-analyzer 进行代码构建分析\n\n" + "npm run analyzer\n" + "```\n\n" + "**测试**\n" + "```js\n" + "// karma mocha chai\n" + "npm run test\n" + "```\n\n" + "## 开发规范 (Standard)\n\n" + "查看[INSTRODUCTION](https://github.com/BiYuqi/webpack-seed/blob/master/INSTRODUCTION.md)\n\n" + "## 接口配置 (Api Setting)\n\n" + "查看[API/README](https://github.com/BiYuqi/webpack-seed/blob/master/src/api/README.md)\n\n" + "## 目录结构 (Source)\n\n" + "查看[INSTRODUCTION](https://github.com/BiYuqi/webpack-seed/blob/master/INSTRODUCTION.md#%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84-source)\n\n" + "## 输出目录 (Output)\n" + "[查看输出](https://github.com/BiYuqi/webpack-seed/tree/gh-pages)\n" + "* dist/\n" + "* ---html\n" + "* ---image\n" + "* ---media\n" + "* ---css\n" + "* ---js\n" + "* ---lib\n" + "* ---index.html\n\n" + "> 注意:如果有音视频等,会被打包在media目录\n\n\n" + "## TODO\n" + "- [x] 添加ejs模板,进行页面(首尾)复用, 页面功能模板渲染\n" + "- [x] mini-css-extract-plugin 提取js内引入scss文件失败, 打包后依然在js文件(已解决)\n" + "- [x] 首页页面模板未完成(单独处理打包)\n" + "- [x] 添加第三方库以链接的方式引入\n" + "- [x] 增加ESLint代码校验\n" + "- [x] 增加两个文件夹,一个是fix IE兼容, 一个是引入的公用库,自动加载第三方库到页面,避免手动填写\n" + "- [x] 增加网站未登录的模板(无header,footer)\n" + "- [x] 添加多样化layout模板支持(示例layout/layoutAuth)\n" + "- [x] 搭建单元测试环境(基于karma mocha chai)\n" + "- [x] 单独抽离配置文件webpack.seed.common.js\n" + "- [ ] 待完善测试用例编写\n" + "- [ ] 添加doc使用说明以及实现思路解析\n\n" + "## DOING\n" + "- [ ] 添加doc使用说明以及实现思路解析\n\n" + "## LONG TODO(Base on master)\n" + "- [ ] 搭建国际化版本\n" + "- [ ] 建立分支web-system (后台管理系统模板)\n" + "- [ ] 添加完整网站demo示例\n" + "- [ ] 大众网站模板\n" + "- [ ] web-mobile(移动端模板)\n\n" + "## 更新日志 (Update log)\n\n" + "查看[CHANGELOG](https://github.com/BiYuqi/webpack-seed/blob/master/CHANGELOG.md)\n\n" + "> 本项目目前接口(使用axios只能支持到IE10+), 项目本身支持IE9+\n\n" + "## 贡献代码\n" + "* 先 Fork (https://github.com/BiYuqi/webpack-seed/fork)\n" + "* 创建分支 (git checkout -b your-idea)\n" + "* 提交更改 (git commit -am 'Fixed something')\n" + "* 推送更改 (git push origin your-idea)\n" + "* 创建一个 Pull Request\n\n" + "> [Pull Request使用](http://www.ruanyifeng.com/blog/2017/07/pull_request.html)\n\n" + "## 参考(Thanks)\n\n" + "本脚手架开发中,ejs模板渲染实现这块参考了[webpack-seed](https://github.com/Array-Huang/webpack-seed), 特此备注"; 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