Regular Expressions 101

Save & Manage Regex

  • Current Version: 1
  • 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
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
Processing...

Test String

Code Generator

Generated Code

import re regex = re.compile(r"(.*?)\"(\w+)\"\s+\"([\w| .\/\\%]+)\"", flags=re.MULTILINE | re.DOTALL) test_str = ("\n" " // General\n" " //-------------------------------------------------------------------------------------------------------------\n" " \"BaseClass\" \"ability_datadriven\"\n" " \"AbilityType\" \"DOTA_ABILITY_TYPE_BASIC\"\n" " \"AbilityBehavior\" \"DOTA_ABILITY_BEHAVIOR_UNIT_TARGET\"\n" " \"AbilityUnitTargetTeam\" \"DOTA_UNIT_TARGET_TEAM_ENEMY\"\n" " \"AbilityUnitTargetType\" \"DOTA_UNIT_TARGET_HERO | DOTA_UNIT_TARGET_BASIC\"\n" " \"AbilityUnitDamageType\" \"DAMAGE_TYPE_MAGICAL\"\n" " \"SpellImmunityType\" \"SPELL_IMMUNITY_ENEMIES_NO\"\n" " \"FightRecapLevel\" \"1\"\n" " \"AbilityTextureName\" \"rooting_shoot\"\n\n" " // Casting\n" " //-------------------------------------------------------------------------------------------------------------\n" " \"AbilityCastRange\" \"500\"\n" " \"AbilityCastPoint\" \"0.3 0.3 0.3 0.3\"\n" " \n" " // Time \n" " //-------------------------------------------------------------------------------------------------------------\n" " \"AbilityCooldown\" \"9.0 8.0 7.0 6.0\"\n\n" " // Cost\n" " //-------------------------------------------------------------------------------------------------------------\n" " \"AbilityManaCost\" \"115 125 140 150\"\n\n" " // Stats\n" " //-------------------------------------------------------------------------------------------------------------\n" " \"AbilityModifierSupportValue\" \"0.5\" // Applies multiple modifiers\n" " \n" " // Special\n" " //-------------------------------------------------------------------------------------------------------------\n" " \"AbilitySpecial\"\n" " {\n" " \"01\"\n" " {\n" " \"var_type\" \"FIELD_INTEGER\"\n" " \"damage_per_second_tooltip\" \"50\"\n" " }\n" " \"02\"\n" " {\n" " \"var_type\" \"FIELD_FLOAT\"\n" " \"duration_tooltip\" \"1.5 2.0 2.5 3.0\"\n" " }\n" " \"03\"\n" " {\n" " \"var_type\" \"FIELD_INTEGER\"\n" " \"hero_damage_tooltip\" \"150 200 250 300\"\n" " }\n" " \"04\"\n" " {\n" " \"var_type\" \"FIELD_FLOAT\"\n" " \"creep_duration_tooltip\" \"10.0 10.0 10.0 10.0\"\n" " }\n" " \"05\"\n" " {\n" " \"var_type\" \"FIELD_INTEGER\"\n" " \"creep_damage_tooltip\" \"1000\"\n" " }\n" " \"06\"\n" " {\n" " \"var_type\" \"FIELD_FLOAT\"\n" " \"damage\" \"100\"\n" " }\n" " // Extra variable\n" " \"07\"\n" " {\n" " \"var_type\" \"FIELD_FLOAT\"\n" " \"stun_duration\" \"0.1\"\n" " }\n" " \"08\"\n" " {\n" " \"var_type\" \"FIELD_FLOAT\"\n" " \"damage_interval\" \"0.5\"\n" " }\n" " \"09\"\n" " {\n" " \"var_type\" \"FIELD_INTEGER\"\n" " \"damage_per_second\" \"25\"\n" " }\n" " \"10\"\n" " {\n" " \"var_type\" \"FIELD_FLOAT\"\n" " \"duration\" \"1.0 1.5 2.0 2.5\"\n" " }\n" " \"11\"\n" " {\n" " \"var_type\" \"FIELD_FLOAT\"\n" " \"creep_duration\" \"9.5 9.5 9.5 9.5\"\n" " }\n" " }\n" " \n" " // Data driven\n" " //-------------------------------------------------------------------------------------------------------------\n" " \"precache\"\n" " {\n" " \"soundfile\" \"soundevents/game_sounds_heroes/game_sounds_crystalmaiden.vsndevts\"\n" " \"particle\" \"particles/leave_bite/leave_bite_06.vpcf\"\n" " \"particle\" \"particles/leave_bite/leave_bite_01.vpcf\"\n" " }\n" " \n" " \"OnSpellStart\"\n" " {\n" " \"TrackingProjectile\"\n" " {\n" " \"Target\" \"TARGET\"\n" " \"EffectName\" \"particles/leave_bite/leave_bite_01.vpcf\"\n" " \"MoveSpeed\" \"2000\"\n" " }\n" " \n" " \"Stun\"\n" " {\n" " \"Target\" \"TARGET\"\n" " \"Duration\" \"%stun_duration\"\n" " }\n" " \n" " \"ApplyModifier\"\n" " {\n" " \"Target\"\n" " {\n" " \"Center\" \"TARGET\"\n" " \"Types\" \"DOTA_UNIT_TARGET_HERO\"\n" " }\n" " \"ModifierName\" \"modifier_frost_bite_root_datadriven\"\n" " \"Duration\" \"%duration\"\n" " }\n" " \n" " \"ApplyModifier\"\n" " {\n" " \"Target\"\n" " {\n" " \"Center\" \"TARGET\"\n" " \"Types\" \"DOTA_UNIT_TARGET_HERO\"\n" " }\n" " \"ModifierName\" \"modifier_frost_bite_damage_datadriven\"\n" " \"Duration\" \"%duration\"\n" " }\n" " \n" " \"ApplyModifier\"\n" " {\n" " \"Target\"\n" " {\n" " \"Center\" \"TARGET\"\n" " \"Types\" \"DOTA_UNIT_TARGET_BASIC\"\n" " }\n" " \"ModifierName\" \"modifier_frost_bite_root_datadriven\"\n" " \"Duration\" \"%creep_duration\"\n" " }\n" " \n" " \"ApplyModifier\"\n" " {\n" " \"Target\"\n" " {\n" " \"Center\" \"TARGET\"\n" " \"Types\" \"DOTA_UNIT_TARGET_BASIC\"\n" " }\n" " \"ModifierName\" \"modifier_frost_bite_damage_datadriven\"\n" " \"Duration\" \"%creep_duration\"\n" " }\n" " \n" " \"FireSound\"\n" " {\n" " \"Target\" \"TARGET\"\n" " \"EffectName\" \"hero_Crystal.frostbite\"\n" " }\n" " }\n" " \n" " \"Modifiers\"\n" " {\n" " \"modifier_frost_bite_root_datadriven\"\n" " {\n" " \"IsPurgable\" \"1\"\n" " \n" " \"EffectName\" \"particles/leave_bite/leave_bite_06.vpcf\"\n" " \n" " \"States\"\n" " {\n" " \"MODIFIER_STATE_ROOTED\" \"MODIFIER_STATE_VALUE_ENABLED\"\n" " \"MODIFIER_STATE_INVISIBLE\" \"MODIFIER_STATE_VALUE_DISABLED\"\n" " }\n" " }\n" " \n" " \"modifier_frost_bite_damage_datadriven\"\n" " {\n" " \"IsPurgable\" \"1\"\n" " \"IsHidden\" \"1\"\n" " \n" " \"OnCreated\"\n" " {\n" " \"Damage\"\n" " {\n" " \"Target\" \"TARGET\"\n" " \"Damage\" \"%damage_per_second\"\n" " \"Type\" \"DAMAGE_TYPE_MAGICAL\"\n" " }\n" " }\n" " \n" " \"ThinkInterval\" \"%damage_interval\"\n" " \"OnIntervalThink\"\n" " {\n" " \"Damage\"\n" " {\n" " \"Target\" \"TARGET\"\n" " \"Damage\" \"%damage_per_second\"\n" " \"Type\" \"DAMAGE_TYPE_MAGICAL\"\n" " }\n" " }\n" " }\n" " }") match = regex.search(test_str) if match: print(f"Match was found at {match.start()}-{match.end()}: {match.group()}") for group_num, group in enumerate(match.groups(), start=1): print(f"Group {group_num} found at {match.start(group_num)}-{match.end(group_num)}: {group}")

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