Regular Expressions 101

Save & Share

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

r"
"
gm

Test String

Code Generator

Generated Code

# coding=utf8 # the above tag defines encoding for this document and is for Python 2.x compatibility import re regex = r"<span style[^>]</span>" test_str = "\"<p>Sau khi đ&atilde; tốn nhiều giấy mực cho thương vụ Benzema tới London, b&aacute;o ch&iacute; Anh lại đang chuyển chủ để sang một c&aacute;i t&ecirc;n kh&aacute;c l&agrave; Edison Cavani khi đang c&oacute; những dấu hiệu cho thấy, HLV Arsene Wenger đang muốn chi&ecirc;u mộ ch&acirc;n s&uacute;t thuộc &lsquo;h&agrave;ng khủng&rsquo; n&agrave;y trước khi thị trường chuyển nhượng năm nay đ&oacute;ng cửa v&agrave;o ng&agrave;y thứ Ba tới.<\\/p> <p style=\\\"text-align: center;\\\"><a href=\\\"http:\\/\\/admin.thethao247.vn\\/files\\/2\\/86\\/cavani.jpg\\\"><img src=\\\"http:\\/\\/admin.thethao247.vn\\/files\\/2\\/86\\/cavani.jpg\\\" \\/><\\/a><\\/p> <p style=\\\"text-align: center;\\\"><span style=\\\"color: #0000ff;\\\">Cavani c&oacute; thể sang London<\\/span><\\/p> <p>Trước đ&oacute;, tiền đạo Real Madrid Karim Benzema đ&atilde; x&oacute;a tan c&aacute;c tin đồn sau khi l&ecirc;n tiếng sẽ ở lại s&acirc;n Bernabeu trong m&ugrave;a giải n&agrave;y. Việc trung phong người Ph&aacute;p cam kết ở lại T&acirc;y Ban Nha khiến Gi&aacute;o sư Wenger buộc phải hướng tầm ngắm sang tiền đạo đang kho&aacute;c &aacute;o PSG Cavani cho những kế hoạch d&agrave;i hơi của Arsenal trong thời gian sắp tới.<\\/p> <p>Ở độ tuổi sung sức của sự nghiệp, Cavani đang l&agrave; mục ti&ecirc;u theo đuổi của cả Arsenal v&agrave; Man United khi những tiền đạo tr&ecirc;n h&agrave;ng c&ocirc;ng của họ chưa cho thấy sự hiệu quả ở m&ugrave;a giải n&agrave;y. Sau nhiều năm &lsquo;thắt lung buộc bụng&rsquo; HLV Wenger cũng đang cho thấy m&igrave;nh kh&ocirc;ng hề thua k&eacute;m c&aacute;c đồng nghiệp khi đ&atilde; bỏ ra 42 triệu cho Mesut Ozil hay 35 triệu bảng để c&oacute; được Sanchez. Điều đ&oacute; cho thấy thương vụ Cavani tới Arsenal l&agrave; vẫn c&ograve;n v&agrave; NHM Ph&aacute;o thủ vẫn c&oacute; thể hi vọng v&agrave;o bản hợp đồng n&agrave;y.<\\/p> <p>Một tin đồn kh&aacute;c l&agrave; việc Arsenal đang &lsquo;rất kết&rsquo; tiền đạo Aleksandr Kokorin của Dynamo Moscow. Anh cũng l&agrave; mục ti&ecirc;u m&agrave; HLV Van Gaal theo đuổi nhưng c&oacute; vẻ tuyển thủ người Nga sẽ đầu qu&acirc;n cho nh&agrave; v&ocirc; địch Ligue 1 PSG d&ugrave; đại diện đội b&oacute;ng Ph&aacute;p v&agrave; ph&iacute;a đối t&aacute;c Nga chưa x&aacute;c nhận về điều n&agrave;y.<\\/p> <p>Li&ecirc;n quan tới vấn đề nh&acirc;n sự của Ph&aacute;o thủ, một tin kh&ocirc;ng vui l&agrave; hậu vệ chủ chốt của họ, Laurent Koscielny đ&atilde; kh&ocirc;ng may gặp phải chấn thương v&agrave; sẽ lỡ hẹn c&ugrave;ng đồng đội đến l&agrave;m kh&aacute;ch tại s&acirc;n St James Park của Newcastle ở trận đấu sớm v&ograve;ng 4 Premier League ng&agrave;y thứ Bảy tới.<\\/p> <p style=\\\"text-align: center;\\\"><a href=\\\"http:\\/\\/admin.thethao247.vn\\/files\\/2\\/86\\/Kos_mert_3418732b_1.jpg\\\"><img src=\\\"http:\\/\\/admin.thethao247.vn\\/files\\/2\\/86\\/Kos_mert_3418732b_1.jpg\\\" \\/><\\/a><\\/p> <p style=\\\"text-align: center;\\\"><span style=\\\"color: #0000ff;\\\">Per-Laurent l&agrave; bộ đ&ocirc;i trung vệ tin cậy nhất của Ph&aacute;o thủ Arsenal l&uacute;c n&agrave;y<\\/span><\\/p> <p>Hậu vệ tuyển Ph&aacute;p đ&atilde; d&iacute;nh chấn thương lưng v&agrave; kh&ocirc;ng thể g&oacute;p mặt c&ugrave;ng đồng đội ở trận h&ograve;a kh&ocirc;ng b&agrave;n thắng của Arsenal trước Liverpool, trong khi đ&oacute; trung vệ Per Mertesacker cũng gặp phải vấn đề sức khỏe nhưng ho&agrave;n to&agrave;n c&oacute; thể quay lại v&agrave;o cuối tuần n&agrave;y. Ở trận đấu h&ocirc;m thứ Hai (24\\/8), lần đầu ti&ecirc;n kể từ th&aacute;ng Tư năm 2012, Ph&aacute;o thủ kh&ocirc;ng c&oacute; sự xuất hiện của bộ đ&ocirc;i Per-Laurent trong một trận đấu. Việc sạch lưới của Arsenal ở v&ograve;ng Ba phải kể tới sự xuất sắc của thủ m&ocirc;n Petr Cech hơn l&agrave; độ vững ch&atilde;i nơi h&agrave;ng hậu vệ, khi m&agrave; họ đang dồn to&agrave;n lực cho sự xuất hiện của một tiền đạo mới. Chắc chắn trong trận đấu sắp tới, h&agrave;ng thủ Arsenal sẽ l&agrave; điều m&agrave; Gi&aacute;o sư Wenger lo ngại nhất sau sự thiếu vắng của những c&aacute;i t&ecirc;n n&agrave;y.<\\/p>\"" matches = re.finditer(regex, test_str, re.MULTILINE) for matchNum, match in enumerate(matches, start=1): print ("Match {matchNum} was found at {start}-{end}: {match}".format(matchNum = matchNum, start = match.start(), end = match.end(), match = match.group())) for groupNum in range(0, len(match.groups())): groupNum = groupNum + 1 print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = match.start(groupNum), end = match.end(groupNum), group = match.group(groupNum))) # Note: for Python 2.7 compatibility, use ur"" to prefix the regex and u"" to prefix the test string and substitution.

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 Python, please visit: https://docs.python.org/3/library/re.html