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

r"
"
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 = "(?:[M|m](?:edical|EDICAL|rn|RN|r|R)|[P|p](?:atient|ATIENT))(?:\\s+(?:record|Record|RECORD))?(?:\\s+(?:id|identification|name|no|number|Id|Identification|Name|No|Number|ID|IDENTIFICATION|NAME|NO|NUMBER))?(?:[\\s#]*)?0(?!0{7})\\d{7}\\b|\\b0(?!0{7})\\d{7}\\s*(?:[M|m](?:edical|EDICAL|r|R|rn|RN)|[P|p](?:atient|ATIENT))(?:\\s+(?:record|Record|RECORD))?(?:\\s+(?:id|name|no|number|Id|Name|No|Number|ID|NAME|NO|NUMBER))?\\b"; final String string = "00000000 GIBBERIGH\n" + "00000000 Gibberigh\n" + "00000000 ME\n" + "00000000 MEDICAL\n" + "00000000 MEDICAL NUMBER\n" + "00000000 MEDICAL RECORD NUMBER\n" + "00000000 MR #\n" + "00000000 MR#\n" + "00000000 MRN\n" + "00000000 MRN #\n" + "00000000 MRN#\n" + "00000000 MRO\n" + "00000000 Me\n" + "00000000 Medical\n" + "00000000 Medical number\n" + "00000000 Medical record number\n" + "00000000 Mr #\n" + "00000000 Mr#\n" + "00000000 Mrn\n" + "00000000 Mrn #\n" + "00000000 Mrn#\n" + "00000000 Mro\n" + "00000000 PATIENT ID\n" + "00000000 PATIENT IDENTIFICATION\n" + "00000000 PATIENT NAME\n" + "00000000 PATIENT NO\n" + "00000000 PATIENT NUMBER\n" + "00000000 Patient id\n" + "00000000 Patient identification\n" + "00000000 Patient name\n" + "00000000 Patient no\n" + "00000000 Patient number\n" + "00000000 gibberigh\n" + "00000000 me\n" + "00000000 medical\n" + "00000000 medical number\n" + "00000000 medical record number\n" + "00000000 mr #\n" + "00000000 mr#\n" + "00000000 mrn\n" + "00000000 mrn #\n" + "00000000 mrn#\n" + "00000000 mro\n" + "00000000 patient id\n" + "00000000 patient identification\n" + "00000000 patient name\n" + "00000000 patient no\n" + "00000000 patient number\n" + "00000000GIBBERIGH\n" + "00000000Gibberigh\n" + "00000000ME\n" + "00000000MEDICAL\n" + "00000000MEDICAL NUMBER\n" + "00000000MEDICAL RECORD NUMBER\n" + "00000000MR #\n" + "00000000MR#\n" + "00000000MRN\n" + "00000000MRN #\n" + "00000000MRN#\n" + "00000000MRO\n" + "00000000Me\n" + "00000000Medical\n" + "00000000Medical number\n" + "00000000Medical record number\n" + "00000000Mr #\n" + "00000000Mr#\n" + "00000000Mrn\n" + "00000000Mrn #\n" + "00000000Mrn#\n" + "00000000Mro\n" + "00000000PATIENT ID\n" + "00000000PATIENT IDENTIFICATION\n" + "00000000PATIENT NAME\n" + "00000000PATIENT NO\n" + "00000000PATIENT NUMBER\n" + "00000000Patient id\n" + "00000000Patient identification\n" + "00000000Patient name\n" + "00000000Patient no\n" + "00000000Patient number\n" + "00000000gibberigh\n" + "00000000me\n" + "00000000medical\n" + "00000000medical number\n" + "00000000medical record number\n" + "00000000mr #\n" + "00000000mr#\n" + "00000000mrn\n" + "00000000mrn #\n" + "00000000mrn#\n" + "00000000mro\n" + "00000000patient id\n" + "00000000patient identification\n" + "00000000patient name\n" + "00000000patient no\n" + "00000000patient number\n" + "00012345 GIBBERIGH\n" + "00012345 Gibberigh\n" + "00012345 ME\n" + "00012345 MEDICAL\n" + "00012345 MEDICAL NUMBER\n" + "00012345 MEDICAL RECORD NUMBER\n" + "00012345 MR #\n" + "00012345 MR#\n" + "00012345 MRN\n" + "00012345 MRN #\n" + "00012345 MRN#\n" + "00012345 MRO\n" + "00012345 Me\n" + "00012345 Medical\n" + "00012345 Medical number\n" + "00012345 Medical record number\n" + "00012345 Mr #\n" + "00012345 Mr#\n" + "00012345 Mrn\n" + "00012345 Mrn #\n" + "00012345 Mrn#\n" + "00012345 Mro\n" + "00012345 PATIENT ID\n" + "00012345 PATIENT IDENTIFICATION\n" + "00012345 PATIENT NAME\n" + "00012345 PATIENT NO\n" + "00012345 PATIENT NUMBER\n" + "00012345 Patient id\n" + "00012345 Patient identification\n" + "00012345 Patient name\n" + "00012345 Patient no\n" + "00012345 Patient number\n" + "00012345 gibberigh\n" + "00012345 me\n" + "00012345 medical\n" + "00012345 medical number\n" + "00012345 medical record number\n" + "00012345 mr #\n" + "00012345 mr#\n" + "00012345 mrn\n" + "00012345 mrn #\n" + "00012345 mrn#\n" + "00012345 mro\n" + "00012345 patient id\n" + "00012345 patient identification\n" + "00012345 patient name\n" + "00012345 patient no\n" + "00012345 patient number\n" + "00012345GIBBERIGH\n" + "00012345Gibberigh\n" + "00012345ME\n" + "00012345MEDICAL\n" + "00012345MEDICAL NUMBER\n" + "00012345MEDICAL RECORD NUMBER\n" + "00012345MR #\n" + "00012345MR#\n" + "00012345MRN\n" + "00012345MRN #\n" + "00012345MRN#\n" + "00012345MRO\n" + "00012345Me\n" + "00012345Medical\n" + "00012345Medical number\n" + "00012345Medical record number\n" + "00012345Mr #\n" + "00012345Mr#\n" + "00012345Mrn\n" + "00012345Mrn #\n" + "00012345Mrn#\n" + "00012345Mro\n" + "00012345PATIENT ID\n" + "00012345PATIENT IDENTIFICATION\n" + "00012345PATIENT NAME\n" + "00012345PATIENT NO\n" + "00012345PATIENT NUMBER\n" + "00012345Patient id\n" + "00012345Patient identification\n" + "00012345Patient name\n" + "00012345Patient no\n" + "00012345Patient number\n" + "00012345gibberigh\n" + "00012345me\n" + "00012345medical\n" + "00012345medical number\n" + "00012345medical record number\n" + "00012345mr #\n" + "00012345mr#\n" + "00012345mrn\n" + "00012345mrn #\n" + "00012345mrn#\n" + "00012345mro\n" + "00012345patient id\n" + "00012345patient identification\n" + "00012345patient name\n" + "00012345patient no\n" + "00012345patient number\n" + "00123456 GIBBERIGH\n" + "00123456 Gibberigh\n" + "00123456 ME\n" + "00123456 MEDICAL\n" + "00123456 MEDICAL NUMBER\n" + "00123456 MEDICAL RECORD NUMBER\n" + "00123456 MR #\n" + "00123456 MR#\n" + "00123456 MRN\n" + "00123456 MRN #\n" + "00123456 MRN#\n" + "00123456 MRO\n" + "00123456 Me\n" + "00123456 Medical\n" + "00123456 Medical number\n" + "00123456 Medical record number\n" + "00123456 Mr #\n" + "00123456 Mr#\n" + "00123456 Mrn\n" + "00123456 Mrn #\n" + "00123456 Mrn#\n" + "00123456 Mro\n" + "00123456 PATIENT ID\n" + "00123456 PATIENT IDENTIFICATION\n" + "00123456 PATIENT NAME\n" + "00123456 PATIENT NO\n" + "00123456 PATIENT NUMBER\n" + "00123456 Patient id\n" + "00123456 Patient identification\n" + "00123456 Patient name\n" + "00123456 Patient no\n" + "00123456 Patient number\n" + "00123456 gibberigh\n" + "00123456 me\n" + "00123456 medical\n" + "00123456 medical number\n" + "00123456 medical record number\n" + "00123456 mr #\n" + "00123456 mr#\n" + "00123456 mrn\n" + "00123456 mrn #\n" + "00123456 mrn#\n" + "00123456 mro\n" + "00123456 patient id\n" + "00123456 patient identification\n" + "00123456 patient name\n" + "00123456 patient no\n" + "00123456 patient number\n" + "00123456GIBBERIGH\n" + "00123456Gibberigh\n" + "00123456ME\n" + "00123456MEDICAL\n" + "00123456MEDICAL NUMBER\n" + "00123456MEDICAL RECORD NUMBER\n" + "00123456MR #\n" + "00123456MR#\n" + "00123456MRN\n" + "00123456MRN #\n" + "00123456MRN#\n" + "00123456MRO\n" + "00123456Me\n" + "00123456Medical\n" + "00123456Medical number\n" + "00123456Medical record number\n" + "00123456Mr #\n" + "00123456Mr#\n" + "00123456Mrn\n" + "00123456Mrn #\n" + "00123456Mrn#\n" + "00123456Mro\n" + "00123456PATIENT ID\n" + "00123456PATIENT IDENTIFICATION\n" + "00123456PATIENT NAME\n" + "00123456PATIENT NO\n" + "00123456PATIENT NUMBER\n" + "00123456Patient id\n" + "00123456Patient identification\n" + "00123456Patient name\n" + "00123456Patient no\n" + "00123456Patient number\n" + "00123456gibberigh\n" + "00123456me\n" + "00123456medical\n" + "00123456medical number\n" + "00123456medical record number\n" + "00123456mr #\n" + "00123456mr#\n" + "00123456mrn\n" + "00123456mrn #\n" + "00123456mrn#\n" + "00123456mro\n" + "00123456patient id\n" + "00123456patient identification\n" + "00123456patient name\n" + "00123456patient no\n" + "00123456patient number\n" + "01234567 GIBBERIGH\n" + "01234567 Gibberigh\n" + "01234567 ME\n" + "01234567 MEDICAL\n" + "01234567 MEDICAL NUMBER\n" + "01234567 MEDICAL RECORD NUMBER\n" + "01234567 MR #\n" + "01234567 MR#\n" + "01234567 MRN\n" + "01234567 MRN #\n" + "01234567 MRN#\n" + "01234567 MRO\n" + "01234567 Me\n" + "01234567 Medical\n" + "01234567 Medical number\n" + "01234567 Medical record number\n" + "01234567 Mr #\n" + "01234567 Mr#\n" + "01234567 Mrn\n" + "01234567 Mrn #\n" + "01234567 Mrn#\n" + "01234567 Mro\n" + "01234567 PATIENT ID\n" + "01234567 PATIENT IDENTIFICATION\n" + "01234567 PATIENT NAME\n" + "01234567 PATIENT NO\n" + "01234567 PATIENT NUMBER\n" + "01234567 Patient id\n" + "01234567 Patient identification\n" + "01234567 Patient name\n" + "01234567 Patient no\n" + "01234567 Patient number\n" + "01234567 gibberigh\n" + "01234567 me\n" + "01234567 medical\n" + "01234567 medical number\n" + "01234567 medical record number\n" + "01234567 mr #\n" + "01234567 mr#\n" + "01234567 mrn\n" + "01234567 mrn #\n" + "01234567 mrn#\n" + "01234567 mro\n" + "01234567 patient id\n" + "01234567 patient identification\n" + "01234567 patient name\n" + "01234567 patient no\n" + "01234567 patient number\n" + "01234567GIBBERIGH\n" + "01234567Gibberigh\n" + "01234567ME\n" + "01234567MEDICAL\n" + "01234567MEDICAL NUMBER\n" + "01234567MEDICAL RECORD NUMBER\n" + "01234567MR #\n" + "01234567MR#\n" + "01234567MRN\n" + "01234567MRN #\n" + "01234567MRN#\n" + "01234567MRO\n" + "01234567Me\n" + "01234567Medical\n" + "01234567Medical number\n" + "01234567Medical record number\n" + "01234567Mr #\n" + "01234567Mr#\n" + "01234567Mrn\n" + "01234567Mrn #\n" + "01234567Mrn#\n" + "01234567Mro\n" + "01234567PATIENT ID\n" + "01234567PATIENT IDENTIFICATION\n" + "01234567PATIENT NAME\n" + "01234567PATIENT NO\n" + "01234567PATIENT NUMBER\n" + "01234567Patient id\n" + "01234567Patient identification\n" + "01234567Patient name\n" + "01234567Patient no\n" + "01234567Patient number\n" + "01234567gibberigh\n" + "01234567me\n" + "01234567medical\n" + "01234567medical number\n" + "01234567medical record number\n" + "01234567mr #\n" + "01234567mr#\n" + "01234567mrn\n" + "01234567mrn #\n" + "01234567mrn#\n" + "01234567mro\n" + "01234567patient id\n" + "01234567patient identification\n" + "01234567patient name\n" + "01234567patient no\n" + "01234567patient number\n" + "12345678 GIBBERIGH\n" + "12345678 Gibberigh\n" + "12345678 ME\n" + "12345678 MEDICAL\n" + "12345678 MEDICAL NUMBER\n" + "12345678 MEDICAL RECORD NUMBER\n" + "12345678 MR #\n" + "12345678 MR#\n" + "12345678 MRN\n" + "12345678 MRN #\n" + "12345678 MRN#\n" + "12345678 MRO\n" + "12345678 Me\n" + "12345678 Medical\n" + "12345678 Medical number\n" + "12345678 Medical record number\n" + "12345678 Mr #\n" + "12345678 Mr#\n" + "12345678 Mrn\n" + "12345678 Mrn #\n" + "12345678 Mrn#\n" + "12345678 Mro\n" + "12345678 PATIENT ID\n" + "12345678 PATIENT IDENTIFICATION\n" + "12345678 PATIENT NAME\n" + "12345678 PATIENT NO\n" + "12345678 PATIENT NUMBER\n" + "12345678 Patient id\n" + "12345678 Patient identification\n" + "12345678 Patient name\n" + "12345678 Patient no\n" + "12345678 Patient number\n" + "12345678 gibberigh\n" + "12345678 me\n" + "12345678 medical\n" + "12345678 medical number\n" + "12345678 medical record number\n" + "12345678 mr #\n" + "12345678 mr#\n" + "12345678 mrn\n" + "12345678 mrn #\n" + "12345678 mrn#\n" + "12345678 mro\n" + "12345678 patient id\n" + "12345678 patient identification\n" + "12345678 patient name\n" + "12345678 patient no\n" + "12345678 patient number\n" + "12345678GIBBERIGH\n" + "12345678Gibberigh\n" + "12345678ME\n" + "12345678MEDICAL\n" + "12345678MEDICAL NUMBER\n" + "12345678MEDICAL RECORD NUMBER\n" + "12345678MR #\n" + "12345678MR#\n" + "12345678MRN\n" + "12345678MRN #\n" + "12345678MRN#\n" + "12345678MRO\n" + "12345678Me\n" + "12345678Medical\n" + "12345678Medical number\n" + "12345678Medical record number\n" + "12345678Mr #\n" + "12345678Mr#\n" + "12345678Mrn\n" + "12345678Mrn #\n" + "12345678Mrn#\n" + "12345678Mro\n" + "12345678PATIENT ID\n" + "12345678PATIENT IDENTIFICATION\n" + "12345678PATIENT NAME\n" + "12345678PATIENT NO\n" + "12345678PATIENT NUMBER\n" + "12345678Patient id\n" + "12345678Patient identification\n" + "12345678Patient name\n" + "12345678Patient no\n" + "12345678Patient number\n" + "12345678gibberigh\n" + "12345678me\n" + "12345678medical\n" + "12345678medical number\n" + "12345678medical record number\n" + "12345678mr #\n" + "12345678mr#\n" + "12345678mrn\n" + "12345678mrn #\n" + "12345678mrn#\n" + "12345678mro\n" + "12345678patient id\n" + "12345678patient identification\n" + "12345678patient name\n" + "12345678patient no\n" + "12345678patient number\n" + "GIBBERIGH 00000000\n" + "GIBBERIGH 00012345\n" + "GIBBERIGH 00123456\n" + "GIBBERIGH 01234567\n" + "GIBBERIGH 12345678\n" + "GIBBERIGH00000000\n" + "GIBBERIGH00012345\n" + "GIBBERIGH00123456\n" + "GIBBERIGH01234567\n" + "GIBBERIGH12345678\n" + "Gibberigh 00000000\n" + "Gibberigh 00012345\n" + "Gibberigh 00123456\n" + "Gibberigh 01234567\n" + "Gibberigh 12345678\n" + "Gibberigh00000000\n" + "Gibberigh00012345\n" + "Gibberigh00123456\n" + "Gibberigh01234567\n" + "Gibberigh12345678\n" + "ME 00000000\n" + "ME 00012345\n" + "ME 00123456\n" + "ME 01234567\n" + "ME 12345678\n" + "ME00000000\n" + "ME00012345\n" + "ME00123456\n" + "ME01234567\n" + "ME12345678\n" + "MEDICAL 00000000\n" + "MEDICAL 00012345\n" + "MEDICAL 00123456\n" + "MEDICAL 01234567\n" + "MEDICAL 12345678\n" + "MEDICAL NUMBER 00000000\n" + "MEDICAL NUMBER 00012345\n" + "MEDICAL NUMBER 00123456\n" + "MEDICAL NUMBER 01234567\n" + "MEDICAL NUMBER 12345678\n" + "MEDICAL NUMBER00000000\n" + "MEDICAL NUMBER00012345\n" + "MEDICAL NUMBER00123456\n" + "MEDICAL NUMBER01234567\n" + "MEDICAL NUMBER12345678\n" + "MEDICAL RECORD NUMBER 00000000\n" + "MEDICAL RECORD NUMBER 00012345\n" + "MEDICAL RECORD NUMBER 00123456\n" + "MEDICAL RECORD NUMBER 01234567\n" + "MEDICAL RECORD NUMBER 12345678\n" + "MEDICAL RECORD NUMBER00000000\n" + "MEDICAL RECORD NUMBER00012345\n" + "MEDICAL RECORD NUMBER00123456\n" + "MEDICAL RECORD NUMBER01234567\n" + "MEDICAL RECORD NUMBER12345678\n" + "MEDICAL00000000\n" + "MEDICAL00012345\n" + "MEDICAL00123456\n" + "MEDICAL01234567\n" + "MEDICAL12345678\n" + "MR # 00000000\n" + "MR # 00012345\n" + "MR # 00123456\n" + "MR # 01234567\n" + "MR # 12345678\n" + "MR #00000000\n" + "MR #00012345\n" + "MR #00123456\n" + "MR #01234567\n" + "MR #12345678\n" + "MR# 00000000\n" + "MR# 00012345\n" + "MR# 00123456\n" + "MR# 01234567\n" + "MR# 12345678\n" + "MR#00000000\n" + "MR#00012345\n" + "MR#00123456\n" + "MR#01234567\n" + "MR#12345678\n" + "MRN # 00000000\n" + "MRN # 00012345\n" + "MRN # 00123456\n" + "MRN # 01234567\n" + "MRN # 12345678\n" + "MRN #00000000\n" + "MRN #00012345\n" + "MRN #00123456\n" + "MRN #01234567\n" + "MRN #12345678\n" + "MRN 00000000\n" + "MRN 00012345\n" + "MRN 00123456\n" + "MRN 01234567\n" + "MRN 12345678\n" + "MRN# 00000000\n" + "MRN# 00012345\n" + "MRN# 00123456\n" + "MRN# 01234567\n" + "MRN# 12345678\n" + "MRN#00000000\n" + "MRN#00012345\n" + "MRN#00123456\n" + "MRN#01234567\n" + "MRN#12345678\n" + "MRN00000000\n" + "MRN00012345\n" + "MRN00123456\n" + "MRN01234567\n" + "MRN12345678\n" + "MRO 00000000\n" + "MRO 00012345\n" + "MRO 00123456\n" + "MRO 01234567\n" + "MRO 12345678\n" + "MRO00000000\n" + "MRO00012345\n" + "MRO00123456\n" + "MRO01234567\n" + "MRO12345678\n" + "Me 00000000\n" + "Me 00012345\n" + "Me 00123456\n" + "Me 01234567\n" + "Me 12345678\n" + "Me00000000\n" + "Me00012345\n" + "Me00123456\n" + "Me01234567\n" + "Me12345678\n" + "Medical 00000000\n" + "Medical 00012345\n" + "Medical 00123456\n" + "Medical 01234567\n" + "Medical 12345678\n" + "Medical number 00000000\n" + "Medical number 00012345\n" + "Medical number 00123456\n" + "Medical number 01234567\n" + "Medical number 12345678\n" + "Medical number00000000\n" + "Medical number00012345\n" + "Medical number00123456\n" + "Medical number01234567\n" + "Medical number12345678\n" + "Medical record number 00000000\n" + "Medical record number 00012345\n" + "Medical record number 00123456\n" + "Medical record number 01234567\n" + "Medical record number 12345678\n" + "Medical record number00000000\n" + "Medical record number00012345\n" + "Medical record number00123456\n" + "Medical record number01234567\n" + "Medical record number12345678\n" + "Medical00000000\n" + "Medical00012345\n" + "Medical00123456\n" + "Medical01234567\n" + "Medical12345678\n" + "Mr # 00000000\n" + "Mr # 00012345\n" + "Mr # 00123456\n" + "Mr # 01234567\n" + "Mr # 12345678\n" + "Mr #00000000\n" + "Mr #00012345\n" + "Mr #00123456\n" + "Mr #01234567\n" + "Mr #12345678\n" + "Mr# 00000000\n" + "Mr# 00012345\n" + "Mr# 00123456\n" + "Mr# 01234567\n" + "Mr# 12345678\n" + "Mr#00000000\n" + "Mr#00012345\n" + "Mr#00123456\n" + "Mr#01234567\n" + "Mr#12345678\n" + "Mrn # 00000000\n" + "Mrn # 00012345\n" + "Mrn # 00123456\n" + "Mrn # 01234567\n" + "Mrn # 12345678\n" + "Mrn #00000000\n" + "Mrn #00012345\n" + "Mrn #00123456\n" + "Mrn #01234567\n" + "Mrn #12345678\n" + "Mrn 00000000\n" + "Mrn 00012345\n" + "Mrn 00123456\n" + "Mrn 01234567\n" + "Mrn 12345678\n" + "Mrn# 00000000\n" + "Mrn# 00012345\n" + "Mrn# 00123456\n" + "Mrn# 01234567\n" + "Mrn# 12345678\n" + "Mrn#00000000\n" + "Mrn#00012345\n" + "Mrn#00123456\n" + "Mrn#01234567\n" + "Mrn#12345678\n" + "Mrn00000000\n" + "Mrn00012345\n" + "Mrn00123456\n" + "Mrn01234567\n" + "Mrn12345678\n" + "Mro 00000000\n" + "Mro 00012345\n" + "Mro 00123456\n" + "Mro 01234567\n" + "Mro 12345678\n" + "Mro00000000\n" + "Mro00012345\n" + "Mro00123456\n" + "Mro01234567\n" + "Mro12345678\n" + "PATIENT ID 00000000\n" + "PATIENT ID 00012345\n" + "PATIENT ID 00123456\n" + "PATIENT ID 01234567\n" + "PATIENT ID 12345678\n" + "PATIENT ID00000000\n" + "PATIENT ID00012345\n" + "PATIENT ID00123456\n" + "PATIENT ID01234567\n" + "PATIENT ID12345678\n" + "PATIENT IDENTIFICATION 00000000\n" + "PATIENT IDENTIFICATION 00012345\n" + "PATIENT IDENTIFICATION 00123456\n" + "PATIENT IDENTIFICATION 01234567\n" + "PATIENT IDENTIFICATION 12345678\n" + "PATIENT IDENTIFICATION00000000\n" + "PATIENT IDENTIFICATION00012345\n" + "PATIENT IDENTIFICATION00123456\n" + "PATIENT IDENTIFICATION01234567\n" + "PATIENT IDENTIFICATION12345678\n" + "PATIENT NAME 00000000\n" + "PATIENT NAME 00012345\n" + "PATIENT NAME 00123456\n" + "PATIENT NAME 01234567\n" + "PATIENT NAME 12345678\n" + "PATIENT NAME00000000\n" + "PATIENT NAME00012345\n" + "PATIENT NAME00123456\n" + "PATIENT NAME01234567\n" + "PATIENT NAME12345678\n" + "PATIENT NO 00000000\n" + "PATIENT NO 00012345\n" + "PATIENT NO 00123456\n" + "PATIENT NO 01234567\n" + "PATIENT NO 12345678\n" + "PATIENT NO00000000\n" + "PATIENT NO00012345\n" + "PATIENT NO00123456\n" + "PATIENT NO01234567\n" + "PATIENT NO12345678\n" + "PATIENT NUMBER 00000000\n" + "PATIENT NUMBER 00012345\n" + "PATIENT NUMBER 00123456\n" + "PATIENT NUMBER 01234567\n" + "PATIENT NUMBER 12345678\n" + "PATIENT NUMBER00000000\n" + "PATIENT NUMBER00012345\n" + "PATIENT NUMBER00123456\n" + "PATIENT NUMBER01234567\n" + "PATIENT NUMBER12345678\n" + "Patient id 00000000\n" + "Patient id 00012345\n" + "Patient id 00123456\n" + "Patient id 01234567\n" + "Patient id 12345678\n" + "Patient id00000000\n" + "Patient id00012345\n" + "Patient id00123456\n" + "Patient id01234567\n" + "Patient id12345678\n" + "Patient identification 00000000\n" + "Patient identification 00012345\n" + "Patient identification 00123456\n" + "Patient identification 01234567\n" + "Patient identification 12345678\n" + "Patient identification00000000\n" + "Patient identification00012345\n" + "Patient identification00123456\n" + "Patient identification01234567\n" + "Patient identification12345678\n" + "Patient name 00000000\n" + "Patient name 00012345\n" + "Patient name 00123456\n" + "Patient name 01234567\n" + "Patient name 12345678\n" + "Patient name00000000\n" + "Patient name00012345\n" + "Patient name00123456\n" + "Patient name01234567\n" + "Patient name12345678\n" + "Patient no 00000000\n" + "Patient no 00012345\n" + "Patient no 00123456\n" + "Patient no 01234567\n" + "Patient no 12345678\n" + "Patient no00000000\n" + "Patient no00012345\n" + "Patient no00123456\n" + "Patient no01234567\n" + "Patient no12345678\n" + "Patient number 00000000\n" + "Patient number 00012345\n" + "Patient number 00123456\n" + "Patient number 01234567\n" + "Patient number 12345678\n" + "Patient number00000000\n" + "Patient number00012345\n" + "Patient number00123456\n" + "Patient number01234567\n" + "Patient number12345678\n" + "gibberigh 00000000\n" + "gibberigh 00012345\n" + "gibberigh 00123456\n" + "gibberigh 01234567\n" + "gibberigh 12345678\n" + "gibberigh00000000\n" + "gibberigh00012345\n" + "gibberigh00123456\n" + "gibberigh01234567\n" + "gibberigh12345678\n" + "me 00000000\n" + "me 00012345\n" + "me 00123456\n" + "me 01234567\n" + "me 12345678\n" + "me00000000\n" + "me00012345\n" + "me00123456\n" + "me01234567\n" + "me12345678\n" + "medical 00000000\n" + "medical 00012345\n" + "medical 00123456\n" + "medical 01234567\n" + "medical 12345678\n" + "medical number 00000000\n" + "medical number 00012345\n" + "medical number 00123456\n" + "medical number 01234567\n" + "medical number 12345678\n" + "medical number00000000\n" + "medical number00012345\n" + "medical number00123456\n" + "medical number01234567\n" + "medical number12345678\n" + "medical record number 00000000\n" + "medical record number 00012345\n" + "medical record number 00123456\n" + "medical record number 01234567\n" + "medical record number 12345678\n" + "medical record number00000000\n" + "medical record number00012345\n" + "medical record number00123456\n" + "medical record number01234567\n" + "medical record number12345678\n" + "medical00000000\n" + "medical00012345\n" + "medical00123456\n" + "medical01234567\n" + "medical12345678\n" + "mr # 00000000\n" + "mr # 00012345\n" + "mr # 00123456\n" + "mr # 01234567\n" + "mr # 12345678\n" + "mr #00000000\n" + "mr #00012345\n" + "mr #00123456\n" + "mr #01234567\n" + "mr #12345678\n" + "mr# 00000000\n" + "mr# 00012345\n" + "mr# 00123456\n" + "mr# 01234567\n" + "mr# 12345678\n" + "mr#00000000\n" + "mr#00012345\n" + "mr#00123456\n" + "mr#01234567\n" + "mr#12345678\n" + "mrn # 00000000\n" + "mrn # 00012345\n" + "mrn # 00123456\n" + "mrn # 01234567\n" + "mrn # 12345678\n" + "mrn #00000000\n" + "mrn #00012345\n" + "mrn #00123456\n" + "mrn #01234567\n" + "mrn #12345678\n" + "mrn 00000000\n" + "mrn 00012345\n" + "mrn 00123456\n" + "mrn 01234567\n" + "mrn 12345678\n" + "mrn# 00000000\n" + "mrn# 00012345\n" + "mrn# 00123456\n" + "mrn# 01234567\n" + "mrn# 12345678\n" + "mrn#00000000\n" + "mrn#00012345\n" + "mrn#00123456\n" + "mrn#01234567\n" + "mrn#12345678\n" + "mrn00000000\n" + "mrn00012345\n" + "mrn00123456\n" + "mrn01234567\n" + "mrn12345678\n" + "mro 00000000\n" + "mro 00012345\n" + "mro 00123456\n" + "mro 01234567\n" + "mro 12345678\n" + "mro00000000\n" + "mro00012345\n" + "mro00123456\n" + "mro01234567\n" + "mro12345678\n" + "patient id 00000000\n" + "patient id 00012345\n" + "patient id 00123456\n" + "patient id 01234567\n" + "patient id 12345678\n" + "patient id00000000\n" + "patient id00012345\n" + "patient id00123456\n" + "patient id01234567\n" + "patient id12345678\n" + "patient identification 00000000\n" + "patient identification 00012345\n" + "patient identification 00123456\n" + "patient identification 01234567\n" + "patient identification 12345678\n" + "patient identification00000000\n" + "patient identification00012345\n" + "patient identification00123456\n" + "patient identification01234567\n" + "patient identification12345678\n" + "patient name 00000000\n" + "patient name 00012345\n" + "patient name 00123456\n" + "patient name 01234567\n" + "patient name 12345678\n" + "patient name00000000\n" + "patient name00012345\n" + "patient name00123456\n" + "patient name01234567\n" + "patient name12345678\n" + "patient no 00000000\n" + "patient no 00012345\n" + "patient no 00123456\n" + "patient no 01234567\n" + "patient no 12345678\n" + "patient no00000000\n" + "patient no00012345\n" + "patient no00123456\n" + "patient no01234567\n" + "patient no12345678\n" + "patient number 00000000\n" + "patient number 00012345\n" + "patient number 00123456\n" + "patient number 01234567\n" + "patient number 12345678\n" + "patient number00000000\n" + "patient number00012345\n" + "patient number00123456\n" + "patient number01234567\n" + "patient number12345678"; 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