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

/
/
g

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#"(?<! {5})(\".+?\": [^\\[{\n]+(?:,|\n))|(?<! {5})(".+?": {[\S\s]+?},)|(?<! {5})(".+?": \[[\S\s]+?\],)"#).unwrap(); let string = "{ \"applicationId\": \"id651979466\", \"lastestVersion\": \"19.10.03\", \"originalUrlBottomTitle\": \"Nguồn <publisherName>\", \"titleUpdate\": \"Bạn đã sử dụng phiên bản cũ!!!\", \"messageUpdate\": \"Hãy cập nhật ứng dụng để trải nghiệm các tính năng mới, hấp dẫn.\", \"linkUpdate\": \"https://itunes.apple.com/app/id651979466\", \"introduce\": { \"title\": \"Đối tác chính thức\", \"introduceURL\": \"https://app.baomoi.com/publisher/list\" }, \"buttonYes\": \"Cập nhật\", \"buttonNo\": \"Để sau\", \"statusUpdate\": 0, \"enableParse\": true, \"enableCrashlytics\": true, \"livescoreUrl\": \"https://baomoi.com/soccer/app\", \"commentCollapseMin\": 7, \"shareZalo\": true, \"loginFacebook\": false, \"shareFacebook\": true, \"shareFacebookMess\": true, \"zal\": true, \"zalInterval\": 259200, \"userLoZalInterval\": 86400, \"show_comment_time_limit\": 86400, \"enableWebm\": true, \"enableRenderAvatarUserName\": true, \"avatarDefaultNames\": [ \"default\" ], \"logArticles\": 3, \"logVideos\": 2, \"show_feed_article_des\": false, \"inapp_noti_default_headline\": \"Báo Mới\", \"QoSLogReqLimit\": 50, \"QoSLogTimeLimit\": 0, \"QoSLogTimeLimitImages\": 0, \"impsLogTime\": 1000, \"impsLogSize\": 20, \"impsPollLogSize\": 1, \"timeReloadAds\": 5, \"defaultMode\": 0, \"defaultModeTablet\": 0, \"defaultModeIP5\": 1, \"maxArticles\": 1000, \"maxVideos\": 200, \"maxHotComments\": 3, \"timeReloadApp\": 1800, \"smallPreset\": \"a300,w200_r4x3,a400x\", \"mediumPreset\": \"a400,w200_r4x3,a500x\", \"largePreset\": \"a500,w300_r4x3,a700x\", \"iPadPreset\": \"a700,w400_r4x3,a800x\", \"iPX_listArticleFontSize\": \"18,20,22\", \"iPX_feedArticleFontSize\": \"18,20,22\", \"iPX_listTitleFontSize\": 17, \"iPX_feedTitleFontSize\": 19, \"iP6_listArticleFontSize\": \"18,20,22\", \"iP6_feedArticleFontSize\": \"18,20,22\", \"iP6_listTitleFontSize\": 18, \"iP6_feedTitleFontSize\": 20, \"iP6P_listArticleFontSize\": \"18,20,22\", \"iP6P_feedArticleFontSize\": \"18,20,22\", \"iP6P_listTitleFontSize\": 18, \"iP6P_feedTitleFontSize\": 20, \"iPad_listArticleFontSize\": \"22,24,26\", \"iPad_feedArticleFontSize\": \"24,26,28\", \"iPad_listTitleFontSize\": 24, \"iPad_feedTitleFontSize\": 26, \"iP5_listArticleFontSize\": \"18,20,22\", \"iP5_feedArticleFontSize\": \"20,22,24\", \"iP5_listTitleFontSize\": 18, \"iP5_feedTitleFontSize\": 22, \"pageRequestCounter\": 15, \"showCounter\": true, \"showLastestNewsButton\": true, \"showSlideBanner\": false, \"videoFormat\": 0, \"allowPreloadVideo\": true, \"wifi_chunkPreloadVideo\": 1, \"3g_chunkPreloadVideo\": 0, \"commentHints\": \"Bình luận phải có ít nhất 3 chữ|Bình luận phải dùng tiếng Việt có dấu.|Bình luận không nói tục, chửi bậy.|Bình luận không chứa liên kết, quảng cáo.\", \"feedName\": \"Theo dõi\", \"feedThumbURL\": [ \"https://baomoi-static.zadn.vn/Uploaded/AppFeedThumb/feedthumb1.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/AppFeedThumb/feedthumb2.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/AppFeedThumb/feedthumb3.jpg\" ], \"feedEmptyScreenMsg\": \"Theo dõi thêm nguồn \\nđể có thêm tin trong danh sách\", \"defaultZoneNewsTab\": \"c_0\", \"fixedZones\": \"Tin nóng|c_0,Tin mới|c_-1\", \"defaultZones\": \"Bóng đá VN|c_87,Bóng đá QT|c_86,Độc & Lạ|c_79,Tình yêu|c_139,Giải trí|c_52,Thế giới|c_119,Pháp luật|c_58,Xe 360|c_145,Công Nghệ|c_53,Ẩm thực|c_84,Làm đẹp|c_138,Sức khỏe|c_82,Du lịch|c_137\", \"allZones\": \"Tin mới|c_-1,Bóng đá VN|c_87,Bóng đá QT|c_86,Độc & Lạ|c_79,Tình yêu|c_139,Giải trí|c_52,Thế giới|c_119,Pháp luật|c_58,Xe 360|c_145,Công Nghệ|c_53,Ẩm thực|c_84,Làm đẹp|c_138,Sức khỏe|c_82,Du lịch|c_137,Nhà đất|c_147,Thời sự|c_144,Thiết bị - Phần cứng|c_136,Kinh tế|c_45,Giáo dục|c_59,Không gian - Kiến trúc|c_150,Thời trang|c_72\", \"updatedZones\": \"Bóng đá VN|c_87\", \"excludedZones\": \"\", \"changedZones\": \"k_Biển Đông|top_228,st_5|top_228\", \"regions\": \"Hà Nội|r_Hà Nội|29,TP. HCM|r_TP. HCM|50,An Giang|r_An Giang|67,Bắc Giang|r_Bắc Giang|98,Bắc Kạn|r_Bắc Kạn|97,Bạc Liêu|r_Bạc Liêu|94,Bắc Ninh|r_Bắc Ninh|99,Bến Tre|r_Bến Tre|71,Bình Định|r_Bình Định|77,Bình Dương|r_Bình Dương|61,Bình Phước|r_Bình Phước|93,Bình Thuận|r_Bình Thuận|86,BR-VT|r_BR-VT|72,Cà Mau|r_Cà Mau|69,Cần Thơ|r_Cần Thơ|65,Cao Bằng|r_Cao Bằng|11,Đà Nẵng|r_Đà Nẵng|43,Đăk Lăk|r_Đăk Lăk|47,Đăk Nông|r_Đăk Nông|48,Điện Biên|r_Điện Biên|27,Đồng Nai|r_Đồng Nai|60,Đồng Tháp|r_Đồng Tháp|66,Gia Lai|r_Gia Lai|81,Hà Giang|r_Hà Giang|23,Hà Nam|r_Hà Nam|90,Hà Tĩnh|r_Hà Tĩnh|38,Hải Dương|r_Hải Dương|34,Hải Phòng|r_Hải Phòng|15,Hậu Giang|r_Hậu Giang|95,Hòa Bình|r_Hòa Bình|28,Hưng Yên|r_Hưng Yên|89,Khánh Hòa|r_Khánh Hòa|79,Kiên Giang|r_Kiên Giang|68,Kon Tum|r_Kon Tum|82,Lai Châu|r_Lai Châu|25,Lâm Đồng|r_Lâm Đồng|49,Lạng Sơn|r_Lạng Sơn|12,Lào Cai|r_Lào Cai|24,Long An|r_Long An|62,Nam Định|r_Nam Định|18,Nghệ An|r_Nghệ An|37,Ninh Bình|r_Ninh Bình|35,Ninh Thuận|r_Ninh Thuận|85,Phú Thọ|r_Phú Thọ|19,Phú Yên|r_Phú Yên|78,Quảng Bình|r_Quảng Bình|73,Quảng Nam|r_Quảng Nam|92,Quảng Ngãi|r_Quảng Ngãi|76,Quảng Ninh|r_Quảng Ninh|14,Quảng Trị|r_Quảng Trị|74,Sóc Trăng|r_Sóc Trăng|83,Sơn La|r_Sơn La|26,Tây Ninh|r_Tây Ninh|70,Thái Bình|r_Thái Bình|17,Thái Nguyên|r_Thái Nguyên|20,Thanh Hóa|r_Thanh Hóa|36,Tiền Giang|r_Tiền Giang|63,Trà Vinh|r_Trà Vinh|84,TT Huế|r_TT Huế|75,Tuyên Quang|r_Tuyên Quang|22,Vĩnh Long|r_Vĩnh Long|64,Vĩnh Phúc|r_Vĩnh Phúc|88,Yên Bái|r_Yên Bái|21\", \"domainIcon\": \"https://baomoi-static.zadn.vn/icon_publishers\", \"topPublishers\": \"VietnamNet|p_23,Tiền Phong|p_20,VTC News|p_83,Zing|p_119,VOV|p_65,VietnamPlus|p_293,PLO|p_114,Infonet|p_240\", \"defaultVideoZones\": [ { \"zoneName\": \"Mới\", \"zoneId\": \"v_-1\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/New/v_-1_1_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/New/v_-1_2_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/New/v_-1_3_20181031.jpg\" ] }, { \"zoneName\": \"Ahihi\", \"zoneId\": \"v_12\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Ahihi/v_12_1_20181031_fixed.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Ahihi/v_12_2_20181031_fixed.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Ahihi/v_12_3_20181031_fixed.jpg\" ] }, { \"zoneName\": \"OMG\", \"zoneId\": \"v_47\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/OMG/v_47_1_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/OMG/v_47_2_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/OMG/v_47_3_20181031.jpg\" ] }, { \"zoneName\": \"2Tek\", \"zoneId\": \"v_43\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Hightek/v_43_1_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Hightek/v_43_2_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Hightek/v_43_3_20181031.jpg\" ] }, { \"zoneName\": \"Bóng đá\", \"zoneId\": \"v_21\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/BongDa/v_21_1_20181108.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/BongDa/v_21_2_20181108.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/BongDa/v_21_3_20181108.jpg\" ] }, { \"zoneName\": \"Cute\", \"zoneId\": \"v_40\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Cute/v_40_1_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Cute/v_40_2_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Cute/v_40_3_20181031.jpg\" ] }, { \"zoneName\": \"Showbiz\", \"zoneId\": \"v_6\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Showbiz/v_6_1_20181226.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Showbiz/v_6_2_20181226.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Showbiz/v_6_3_20181226.jpg\" ] }, { \"zoneName\": \"Sống\", \"zoneId\": \"v_37\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Ngam/v_37_1_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Ngam/v_37_2_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Ngam/v_37_3_20181031.jpg\" ] }, { \"zoneName\": \"Lifestyle\", \"zoneId\": \"v_16\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/LifeStyle/v_16_1_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/LifeStyle/v_16_2_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/LifeStyle/v_16_3_20181031.jpg\" ] }, { \"zoneName\": \"News\", \"zoneId\": \"v_1\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/News/v_1_1_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/News/v_1_2_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/News/v_1_3_20181031.jpg\" ] }, { \"zoneName\": \"Top\", \"zoneId\": \"v_0\", \"images\": [ \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Top/v_0_1_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Top/v_0_2_20181031.jpg\", \"https://baomoi-static.zadn.vn/Uploaded/VideoSubTabImgs/Top/v_0_3_20181031.jpg\" ] } ], \"pubProfileTabsName\": \"1|Tổng hợp,9|Video,13|Poll,15|Q&A\", \"logChannels\": 2, \"maxChannelContents\": 10, \"channelFontSize\": \"13,14,14\", \"articleVideoMode\": 1, \"articleViewMode\": 1, \"tapForSoundShowingTime\": 1, \"tapForSoundText\": \"Bấm video để mở tiếng\", \"numberOfInsertedArticles\": 3, \"recommendListRefreshInterval\": 1800000, \"showRecommendGroup\": false, \"recommendGroupName\": \"CÓ THỂ BẠN QUAN TÂM\", \"recommendGroupBtnText\": \"Xem thêm\", \"suggestReplyCondition\": 3, \"hideArticleReasonsDefault\": \"Bạo lực|content,Đồi trụy|content,Phản cảm|content,Xuyên tạc|content,Kỳ thị địa phương|content\", \"popupHideArticleMsg\": \"Vui lòng chọn các nguyên nhân khiến bạn không thích bài viết này để chúng tôi có thể đề xuất tin cho bạn tốt hơn\", \"reportArticleReasons\": \"Tin gốc đã gỡ|original_removed,Tin gốc đã cập nhật|original_updated,Bạo lực|content,Đồi trụy|content,Phản cảm|content,Xuyên tạc|content,Kỳ thị địa phương|content,Ý kiến khác...|other\", \"popupReportArticleMsg\": \"Vui lòng chọn các nguyên nhân bạn muốn báo cáo nội dung bài viết này\", \"reportVideoReasons\": \"Tin gốc đã gỡ|original_removed,Tin gốc đã cập nhật|original_updated,Bạo lực|content,Đồi trụy|content,Phản cảm|content,Xuyên tạc|content,Kỳ thị địa phương|content,Ý kiến khác...|other\", \"popupReportVideoMsg\": \"Vui lòng chọn các nguyên nhân bạn muốn báo cáo nội dung video này\", \"reportCommentReasons\": \"Bạo lực|comment,Đồi trụy|comment,Phản cảm|comment,Xuyên tạc|comment,Kỳ thị địa phương|comment,Spam|comment,Ý kiến khác...|other\", \"popupReportCommentMsg\": \"Vui lòng chọn các nguyên nhân báo xấu bình luận này của người dùng %s\", \"stepToShowTripleCell\": 0, \"appNavBarBg\": \"https://baomoi-static.zadn.vn/Uploaded/Bao_BD/nav_bar_bg_default@3x.png\", \"nativeAdsReportMessage\": \"Chúng tôi sẽ cố gắng hạn chế hiển thị quảng cáo này đến bạn.\", \"nativeAdsReportPopupMsg\": \"Vui lòng chọn các nguyên nhân báo xấu quảng cáo này\", \"articleVideoAutoPlay\": true, \"listVideoAutoPlay\": true, \"listVideoAutoPlayNext\": true, \"listTopCmtArticleCondition\": \"50,200,500\", \"replyLoadMoreAmount\": 10, \"articleTopCommentGroup\": true, \"coverageEnable\": true, \"articleCmtBoxHiddenEnable\": true, \"articleViewCloseBtnCondition\": 2, \"sectionBoxesEnable\": [ 0, 1, 2, 3, 4, 10, 11, 20, 30, 40 ], \"content_type\": { \"article\": [ 1 ], \"video\": [ 9 ], \"topic\": [ 5, 6, 7 ], \"qaQuestion\": [ 15 ], \"qaAnswer\": [ 16 ], \"poll\": [ 13 ], \"comment\": [ 18 ] }, \"qaHistorySize\": 40 }"; // 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/