Regular Expressions 101

Save & Share

  • Save new Regex
    ctrl+s
  • Update 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
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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/

Test String

Code Generator

Generated Code

const regex = /.*Patient [N|n]ame:(?<patName>[\w\s,.'-]+).*/; // Alternative syntax using RegExp constructor // const regex = new RegExp('.*Patient [N|n]ame:(?<patName>[\\w\\s,.\'-]+).*', '') const str = `5:50 AM 54 yr old male restrained belted driver involved in head on collision accident going 50 mph. Patient transferred from Danbury hospital with L ankle and open leg fracture. Per EMS patient intubated due injuries and because patient agitated, in pain and uncooperative with staff. Per EMS injury related to long extrication time of 25min/steering wheel and dash board was on patient leg. Patient sedated on propofol drip. Per EMS ativan, 700mcg of fentanyl, 3L of fluid, zofran and tetanus administered at Danbury hospital. Also leg splinted via immbolizer. Per EMS patient has possible hemothorax. Labs sent. Patient to go to CT scan. 0630-Per CT scan waiting for protocol. 0630-patient to go to xray instead. Social Work Assessment Patient Demographics and History: Patient name: Norman Bates ONE: MR5968541 Date of Birth: 3/23/1964 SOCIAL WORK ASSESSMENT Patient Name: Norman Bates Medical TWO: MR5968541 Date of Birth: 3/23/1964 Social Work Assessment Adult Most Recent Value Admission Information Document Type Clinical Assessment Assessment has been completed with in 30 days of this encounter Yes, I have reviewed the most recent assessment and entered updates Prior Assesment Date 07/28/18 Assessment has been completed within this encounter I have reviewed the most recent assessment and entered updates Reason for Encounter -- [Full Trauma.] Source of Information other Record Reviewed plan of care, patient profile Level of Care Emergency Department Social Work Service Line Emergency Department - Adult Assessment has been completed with in 30 days of this encounter Yes, I have reviewed the most recent assessment and entered updates Language Needed None, Patient Speaks English Update to Services: No changes to this area occurred since the last assessment Abuse Screen Able to respond to abuse questions No Mandated Referral Mandated Report Required yes Referral made to Police Mental Status Appearance appears stated age Suicidality Suicidality Unable to Assess Homicidality Homicidality Unable to Assess Update to Homicidality: No changes to this area occurred since the last assessment Alcohol Use Alcohol Use Alcohol Use Substance Use Substance Use Unable to assess Acute Event Patient was referred by Med/Surg Team Transported to Emergency Department via Ambulance If in ED, patient has been medically cleared by the ED No Narrative/Signoff Identified Clinical/Disposition, Issues/Barriers: Full Trauma. Patient intubated. Danbury EMT Staff report indicated pt was involved in MVC. Pt's mother is aware of his status. Writer unable to complete full SW assessment at this time Collaboration with Treatment Team/Community Providers/Family: Consulted with EMT Next Steps/Plan (including hand-off): Case passed on to Trauma SW. Signature: Winsome Meller's LC SW Contact Information: 203 412-3254 7:37 AM 50mcg Fentanyl bolus given for agitation during XRAY 7:40 AM Propofol infusion increased to 35 mcg/kg/min for continued agitation and restlessness 7:43 AM 50 mcg propofol bolus given for sedation 8:08 AM 50mcg Fentanyl bolus given for increased agitation during splinting by ortho Yale New Haven Hospital-Ysc Spiritual Care Note Purpose: Referral Source: Nurse Observation: People present/Information Obtained From: Other (Comment) (ED Staff) Emotional Mood: Unable to assess Quality of Relational Support: Unable to Assess Subjective: MVC. Pt unavailable for spiritual assessment at this time. Will ask incoming on-call for follow up. Spiritual Assessment: Referral Source: Nurse Information Obtained From: Other (Comment) (ED Staff) Mood: Unable to assess Relational Support Quality of Relational Support: Unable to Assess FICA: FICA Spiritual Assessment Tool Need for spiritual support : Unable to assess Spiritual Care Comment: Adult trauma. NA Spiritual Interventions: Spiritual Intervention Index **Date of Spiritual Visit: 07/28/18 Visit Type: New Patient, Initial Visit Intervention Type: Crisis Call Crisis Call Type: Adult Trauma Responding Chaplain: On-Call Chaplain Consulted With: Nurse Spiritual/Religious Support Provided: Companionship Outcome: Plan: Chaplain remains available for support as/if needed. Total Consult Time: 15 minutes Signed: Chaplain Charles Kamano, available via on-call 24/7 pager #187/12651. 7/28/2018 8:12 AM`; let m; if ((m = regex.exec(str)) !== null) { // 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