Regular Expressions 101

Save & Share

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

/
/
g

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"^[^\t]*" test_str = ("__consumer_offsets 50 3 compact 11.5 kB \n" "_schemas 1 3 compact 576 B \n" "euler.public.apartment 1 3 delete 2.53 GB \n" "euler.public.apartment_accounts 1 3 delete 159 MB \n" "euler.public.apartment_bind_qr_codes 1 3 delete 4.73 MB \n" "euler.public.apartment_cameras 1 3 delete 65.7 MB \n" "euler.public.apartment_favorites 1 3 delete 2.97 MB \n" "euler.public.apartment_plans 1 3 delete 114 kB \n" "euler.public.apartment_property 1 3 delete 2.28 MB \n" "euler.public.apartment_scope_access_rel 1 3 delete 17.7 kB \n" "euler.public.app_schema 1 3 delete 1.67 MB \n" "euler.public.board_map_buildings_tags 1 3 delete 961 kB \n" "euler.public.building 1 3 delete 18.7 MB \n" "euler.public.building_cameras 1 3 delete 940 kB \n" "euler.public.building_coordinates 1 3 delete 729 kB \n" "euler.public.building_enterprise 1 3 delete 407 kB \n" "euler.public.building_images 1 3 delete 136 kB \n" "euler.public.business_center 1 3 delete 6.04 kB \n" "euler.public.cctv_cameras_apartments 1 3 delete 422 MB \n" "euler.public.cctv_cameras_buildings 1 3 delete 7.57 MB \n" "euler.public.cctv_cameras_complex 1 3 delete 2.58 kB \n" "euler.public.cctv_cameras_entrances 1 3 delete 3.65 MB \n" "euler.public.cctv_cameras_properties 1 3 delete 2.56 MB \n" "euler.public.comparison_of_meters_readings_buildings_rel 1 3 delete 110 kB \n" "euler.public.comparison_of_meters_readings_registry 1 3 delete 1.3 MB \n" "euler.public.complex 1 3 delete 2.16 MB \n" "euler.public.complexes_mortgage 1 3 delete 1.37 kB \n" "euler.public.construction_stage_configuration 1 3 delete 7.84 kB \n" "euler.public.debtors 1 3 delete 4.07 kB \n" "euler.public.device 1 3 delete 5.66 GB \n" "euler.public.enterprises_buildings 1 3 delete 1.66 MB \n" "euler.public.entrance 1 3 delete 8.17 MB \n" "euler.public.guard_manual_vehicle_parking_slot_rel 1 3 delete 221 kB \n" "euler.public.house_vote_answers_signature 1 3 delete 121 kB \n" "euler.public.house_vote_building_rel 1 3 delete 285 kB \n" "euler.public.journal 1 3 delete 419 MB \n" "euler.public.long_term_events 1 3 delete 9.7 GB \n" "euler.public.news 1 3 delete 36.1 MB \n" "euler.public.news_ext_building_rel 1 3 delete 16.8 MB \n" "euler.public.parking_history 1 3 delete 1.92 MB \n" "euler.public.parking_lots 1 3 delete 371 kB \n" "euler.public.parking_lots_buildings 1 3 delete 536 kB \n" "euler.public.parking_rent_enterprises 1 3 delete 2.6 MB \n" "euler.public.parking_slot_loading_zone_rel 1 3 delete 2.69 kB \n" "euler.public.parking_slot_reservation 1 3 delete 81.7 MB \n" "euler.public.parking_slots 1 3 delete 82.6 MB \n" "euler.public.parking_slots_vehicles 1 3 delete 4.75 MB \n" "euler.public.parking_zones 1 3 delete 636 kB \n" "euler.public.parking_zones_price 1 3 delete 134 kB \n" "euler.public.polls_buildings 1 3 delete 625 kB \n" "euler.public.private_parking_slot_invoice 1 3 delete 65.4 kB \n" "euler.public.properties 1 3 delete 4.82 MB \n" "euler.public.properties_ownership_archive 1 3 delete 338 kB \n" "euler.public.property_buildings 1 3 delete 3.35 MB \n" "euler.public.property_external_crm_relation 1 3 delete 24.1 kB \n" "euler.public.property_photo 1 3 delete 103 kB \n" "euler.public.rents 1 3 delete 4.79 MB \n" "euler.public.rooms 1 3 delete 79.5 MB \n" "euler.public.scud_pass 1 3 delete 5.23 GB \n" "euler.public.scud_pass_apartment_rel 1 3 delete 241 kB \n" "euler.public.service_meters 1 3 delete 84.1 kB \n" "euler.public.splashscreens 1 3 delete 8.7 kB \n" "euler.public.stories_building_rel 1 3 delete 30.3 kB \n" "euler.public.stories_complex_rel 1 3 delete 2.56 kB \n" "euler.public.stuff_pass 1 3 delete 36 MB \n" "euler.public.stuff_pass_car_parking 1 3 delete 14.2 MB \n" "euler.public.ticket_external_service_building_rel 1 3 delete 43.6 kB \n" "euler.public.ticket_type_building_rel 1 3 delete 28.4 kB \n" "euler.public.tickets 1 3 delete 122 MB \n" "euler.public.tri_device_object_rel 1 3 delete 27.9 kB \n" "euler.public.tri_geo_point_object_rel 1 3 delete 7.75 kB \n" "euler.public.user_apartment_compl 1 3 delete 1.1 GB \n" "euler.public.user_apartment_requests 1 3 delete 14.5 MB \n" "euler.public.userdata_buildings 1 3 delete 3.08 kB \n" "euler.public.userdata_business 1 3 delete 10.3 MB \n" "euler.public.userdata_parking_slots 1 3 delete 35.6 MB \n" "euler.public.userdata_properties 1 3 delete 536 kB \n" "euler.public.userdata_property_rel 1 3 delete 1.27 MB \n" "euler.public.userdata_statuses_rel 1 3 delete 63.8 MB \n" "euler.public.userdata_titles 1 3 delete 264 kB \n" "uni_configs 1 1 compact 29.6 kB \n" "uni_offsets 25 1 compact 2.79 kB \n" "uni_statuses 5 1 compact 277 kB \n") matches = re.finditer(regex, test_str) 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