Regular Expressions 101

Save & Manage Regex

  • Current Version: 4
  • Save & Share
  • Community Library

Flavor

  • PCRE2 (PHP)
  • ECMAScript (JavaScript)
  • Python
  • Golang
  • Java
  • .NET 7.0 (C#)
  • Rust
  • PCRE (Legacy)
  • Regex Flavor Guide

Function

  • Match
  • Substitution
  • List
  • Unit Tests
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
  • 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
Processing...

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)(?=\d{2}\s+[A-Z][a-z]{2}\s+\w{2})(.+?)(?:(?=\d{2}\s+[A-Z][a-z]{2}\s+\w{2})|$)").unwrap(); let string = "31 Jul FR 0135 HKG MEL 33K 18:00 19:44 01 Aug SA 06:40 07:10 11:10 02 Aug SU 0134 MEL HKG 33K 06:40 07:37 15:21 15:51 11:11 03 Aug MO G 04 Aug TU 0905 HKG MNL 330 20:50 22:52 05 Aug WE 00:58 0912 MNL HKG 330 08:32 10:36 11:06 14:16 06 Aug TH T2024 P2 19:00 19:00 07 Aug FR 00:30 00:30 05:30 T2314 2R 22:00 22:00 08 Aug SA 06:00 06:00 08:00 09 Aug SU G 10 Aug MO G 11 Aug TU R13 06:00 06:00 06:06 06:06 00:06 0699 HKG BOM 33G 16:20 17:53 21:07 21:37 07:47 12 Aug WE 13 Aug TH RPT 00:00 00:00 02:45 02:45 02:45 14 Aug FR 0660 BOM HKG 33G 03:05 04:15 12:48 13:18 07:43 15 Aug SA R13 06:00 06:00 11:23 11:23 05:23 T1514 CW 14:00 14:00 19:30 19:30 05:30 16 Aug SU 0494 HKG TPE 33G 10:30 12:16 14:08 0495 TPE HKG 33G 14:59 16:43 17:13 06:43 17 Aug MO O 18 Aug TU G 19 Aug WE 0697 HKG DEL 33G 19:05 21:27 20 Aug TH 00:28 00:58 08:23 21 Aug FR 0694 DEL HKG 33K 01:30 02:30 10:45 11:15 07:15 MED HC 22 Aug SA G 23 Aug SU G 24 Aug MO G 25 Aug TU 0767 HKG SGN 33E 07:30 08:40 10:15 0766 SGN HKG 33E 11:20 15:10 15:40 08:10 26 Aug WE G 27 Aug TH G 28 Aug FR 0699 HKG BOM 33G 16:20 17:30 21:20 21:50 08:00 29 Aug SA 0696 BOM HKG 33G 21:30 22:30 30 Aug SU 07:00 07:30 07:30 31 Aug MO 0564 HKG TPE 330 12:00 13:10 14:55 0564 TPE KIX 330 16:05 20:00 20:30 07:30"; // 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/