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

/
/
gs

Test String

Code Generator

Generated Code

// include the latest version of the regex crate in your Cargo.toml extern crate regex; use regex::Regex; fn main() { let regex = Regex::new(r#"(?s)<EventTypeCode csd-code=\"(?<myEventTypeCode>\w{3}\-\d{2})\""#).unwrap(); let string = " <85>1 2020-03-22T18:00:44.389Z hcoxadepdtest01-app06-icwpxs01.net.swisscom-health.it icw-chr 48261 IHE+RFC-3881 - <?xml version=\"1.0\" encoding=\"UTF-8\"?> <AuditMessage> <EventIdentification EventActionCode=\"E\" EventDateTime=\"2020-03-22T18:00:44.388Z\" EventOutcomeIndicator=\"0\"> <EventID csd-code=\"110112\" codeSystemName=\"DCM\" originalText=\"Query\" /> <EventTypeCode csd-code=\"ITI-18\" codeSystemName=\"IHE Transactions\" originalText=\"Registry Stored Query\" /> </EventIdentification> <ActiveParticipant UserID=\"2f66e56b-7d4e-4fb3-86ad-ba53a2208b5f\" AlternativeUserID=\"48261\" UserName=\"\" UserIsRequestor=\"true\" NetworkAccessPointID=\"10.1.44.2\" NetworkAccessPointTypeCode=\"2\"> <RoleIDCode csd-code=\"110153\" codeSystemName=\"DCM\" originalText=\"Source Role ID\" /> </ActiveParticipant> <ActiveParticipant UserID=\"1111111111139\" UserName=\"Gabriela Brunner-Mühlethaler\" UserIsRequestor=\"true\"> <RoleIDCode csd-code=\"HCP\" codeSystemName=\"2.16.756.5.30.1.127.3.10.6\" originalText=\"Behandelnde(r)\" /> </ActiveParticipant> <ActiveParticipant UserID=\"Internal\" UserIsRequestor=\"false\"> <RoleIDCode csd-code=\"110152\" codeSystemName=\"DCM\" originalText=\"Destination Role ID\" /> </ActiveParticipant> <AuditSourceIdentification AuditEnterpriseSiteID=\"2.16.756.5.30.1.194\" AuditSourceID=\"hcoxadepdtest01-app06-icwpxs01\"> <AuditSourceTypeCode csd-code=\"9\" codeSystemName=\"DCM\" originalText=\"Other\" /> </AuditSourceIdentification> <ParticipantObjectIdentification ParticipantObjectID=\"304909^^^&amp;2.16.756.5.30.1.194.3.1.1&amp;ISO\" ParticipantObjectTypeCode=\"1\" ParticipantObjectTypeCodeRole=\"1\"> <ParticipantObjectIDTypeCode csd-code=\"2\" codeSystemName=\"RFC-3881\" originalText=\"Patient Number\" /> </ParticipantObjectIdentification> <ParticipantObjectIdentification ParticipantObjectID=\"urn:uuid:10b545ea-725c-446d-9b95-8aeb444eddf3\" ParticipantObjectTypeCode=\"2\" ParticipantObjectTypeCodeRole=\"24\"> <ParticipantObjectIDTypeCode csd-code=\"ITI-18\" codeSystemName=\"IHE Transactions\" originalText=\"Registry Stored Query\" /> <ParticipantObjectQuery>PD94bWwgdmVyc2lvbj0iMS4w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Wx1ZUxpc3Q+CiAgICAgICAgICAgICAgICA8VmFsdWU+KCd1cm46b2FzaXM6bmFtZXM6dGM6ZWJ4bWwtcmVncmVwOlN0YXR1c1R5cGU6QXBwcm92ZWQnKTwvVmFsdWU+CiAgICAgICAgICAgICAgICA8VmFsdWU+KCd1cm46b2FzaXM6bmFtZXM6dGM6ZWJ4bWwtcmVncmVwOlN0YXR1c1R5cGU6RGVwcmVjYXRlZCcpPC9WYWx1ZT4KICAgICAgICAgICAgPC9WYWx1ZUxpc3Q+CiAgICAgICAgPC9TbG90PgogICAgICAgIDxTbG90IG5hbWU9IiRYRFNTdWJtaXNzaW9uU2V0U3RhdHVzIj4KICAgICAgICAgICAgPFZhbHVlTGlzdD4KICAgICAgICAgICAgICAgIDxWYWx1ZT4oJ3VybjpvYXNpczpuYW1lczp0YzplYnhtbC1yZWdyZXA6U3RhdHVzVHlwZTpBcHByb3ZlZCcpPC9WYWx1ZT4KICAgICAgICAgICAgPC9WYWx1ZUxpc3Q+CiAgICAgICAgPC9TbG90PgogICAgICAgIDxTbG90IG5hbWU9IiRYRFNGb2xkZXJTdGF0dXMiPgogICAgICAgICAgICA8VmFsdWVMaXN0PgogICAgICAgICAgICAgICAgPFZhbHVlPigndXJuOm9hc2lzOm5hbWVzOnRjOmVieG1sLXJlZ3JlcDpTdGF0dXNUeXBlOkFwcHJvdmVkJyk8L1ZhbHVlPgogICAgICAgICAgICA8L1ZhbHVlTGlzdD4KICAgICAgICA8L1Nsb3Q+CiAgICA8L0FkaG9jUXVlcnk+CjwvbnMzOkFkaG9jUXVlcnlSZXF1ZXN0Pgo=</ParticipantObjectQuery> <ParticipantObjectDetail type=\"QueryEncoding\" value=\"VVRGLTg=\" /> <ParticipantObjectDetail type=\"urn:ihe:iti:xca:2010:homeCommunityId\" value=\"Mi4xNi43NTYuNS4zMC4xLjE5NA==\" /> </ParticipantObjectIdentification> </AuditMessage> "; // result will be an iterator over tuples containing the start and end indices for each match in the string let result = regex.captures_iter(string); for mat in result { println!("{:?}", mat); } }

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 Rust, please visit: https://docs.rs/regex/latest/regex/