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
  • Match everything enclosed
    (?:...)
  • Capture everything enclosed
    (...)
  • 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

/
/
ms

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#"(?ms)(.*?)"(\w+)"\s+"([\w| .\/\\%]+)""#).unwrap(); let string = " // General //------------------------------------------------------------------------------------------------------------- \"BaseClass\" \"ability_datadriven\" \"AbilityType\" \"DOTA_ABILITY_TYPE_BASIC\" \"AbilityBehavior\" \"DOTA_ABILITY_BEHAVIOR_UNIT_TARGET\" \"AbilityUnitTargetTeam\" \"DOTA_UNIT_TARGET_TEAM_ENEMY\" \"AbilityUnitTargetType\" \"DOTA_UNIT_TARGET_HERO | DOTA_UNIT_TARGET_BASIC\" \"AbilityUnitDamageType\" \"DAMAGE_TYPE_MAGICAL\" \"SpellImmunityType\" \"SPELL_IMMUNITY_ENEMIES_NO\" \"FightRecapLevel\" \"1\" \"AbilityTextureName\" \"rooting_shoot\" // Casting //------------------------------------------------------------------------------------------------------------- \"AbilityCastRange\" \"500\" \"AbilityCastPoint\" \"0.3 0.3 0.3 0.3\" // Time //------------------------------------------------------------------------------------------------------------- \"AbilityCooldown\" \"9.0 8.0 7.0 6.0\" // Cost //------------------------------------------------------------------------------------------------------------- \"AbilityManaCost\" \"115 125 140 150\" // Stats //------------------------------------------------------------------------------------------------------------- \"AbilityModifierSupportValue\" \"0.5\" // Applies multiple modifiers // Special //------------------------------------------------------------------------------------------------------------- \"AbilitySpecial\" { \"01\" { \"var_type\" \"FIELD_INTEGER\" \"damage_per_second_tooltip\" \"50\" } \"02\" { \"var_type\" \"FIELD_FLOAT\" \"duration_tooltip\" \"1.5 2.0 2.5 3.0\" } \"03\" { \"var_type\" \"FIELD_INTEGER\" \"hero_damage_tooltip\" \"150 200 250 300\" } \"04\" { \"var_type\" \"FIELD_FLOAT\" \"creep_duration_tooltip\" \"10.0 10.0 10.0 10.0\" } \"05\" { \"var_type\" \"FIELD_INTEGER\" \"creep_damage_tooltip\" \"1000\" } \"06\" { \"var_type\" \"FIELD_FLOAT\" \"damage\" \"100\" } // Extra variable \"07\" { \"var_type\" \"FIELD_FLOAT\" \"stun_duration\" \"0.1\" } \"08\" { \"var_type\" \"FIELD_FLOAT\" \"damage_interval\" \"0.5\" } \"09\" { \"var_type\" \"FIELD_INTEGER\" \"damage_per_second\" \"25\" } \"10\" { \"var_type\" \"FIELD_FLOAT\" \"duration\" \"1.0 1.5 2.0 2.5\" } \"11\" { \"var_type\" \"FIELD_FLOAT\" \"creep_duration\" \"9.5 9.5 9.5 9.5\" } } // Data driven //------------------------------------------------------------------------------------------------------------- \"precache\" { \"soundfile\" \"soundevents/game_sounds_heroes/game_sounds_crystalmaiden.vsndevts\" \"particle\" \"particles/leave_bite/leave_bite_06.vpcf\" \"particle\" \"particles/leave_bite/leave_bite_01.vpcf\" } \"OnSpellStart\" { \"TrackingProjectile\" { \"Target\" \"TARGET\" \"EffectName\" \"particles/leave_bite/leave_bite_01.vpcf\" \"MoveSpeed\" \"2000\" } \"Stun\" { \"Target\" \"TARGET\" \"Duration\" \"%stun_duration\" } \"ApplyModifier\" { \"Target\" { \"Center\" \"TARGET\" \"Types\" \"DOTA_UNIT_TARGET_HERO\" } \"ModifierName\" \"modifier_frost_bite_root_datadriven\" \"Duration\" \"%duration\" } \"ApplyModifier\" { \"Target\" { \"Center\" \"TARGET\" \"Types\" \"DOTA_UNIT_TARGET_HERO\" } \"ModifierName\" \"modifier_frost_bite_damage_datadriven\" \"Duration\" \"%duration\" } \"ApplyModifier\" { \"Target\" { \"Center\" \"TARGET\" \"Types\" \"DOTA_UNIT_TARGET_BASIC\" } \"ModifierName\" \"modifier_frost_bite_root_datadriven\" \"Duration\" \"%creep_duration\" } \"ApplyModifier\" { \"Target\" { \"Center\" \"TARGET\" \"Types\" \"DOTA_UNIT_TARGET_BASIC\" } \"ModifierName\" \"modifier_frost_bite_damage_datadriven\" \"Duration\" \"%creep_duration\" } \"FireSound\" { \"Target\" \"TARGET\" \"EffectName\" \"hero_Crystal.frostbite\" } } \"Modifiers\" { \"modifier_frost_bite_root_datadriven\" { \"IsPurgable\" \"1\" \"EffectName\" \"particles/leave_bite/leave_bite_06.vpcf\" \"States\" { \"MODIFIER_STATE_ROOTED\" \"MODIFIER_STATE_VALUE_ENABLED\" \"MODIFIER_STATE_INVISIBLE\" \"MODIFIER_STATE_VALUE_DISABLED\" } } \"modifier_frost_bite_damage_datadriven\" { \"IsPurgable\" \"1\" \"IsHidden\" \"1\" \"OnCreated\" { \"Damage\" { \"Target\" \"TARGET\" \"Damage\" \"%damage_per_second\" \"Type\" \"DAMAGE_TYPE_MAGICAL\" } } \"ThinkInterval\" \"%damage_interval\" \"OnIntervalThink\" { \"Damage\" { \"Target\" \"TARGET\" \"Damage\" \"%damage_per_second\" \"Type\" \"DAMAGE_TYPE_MAGICAL\" } } } }"; // result will be a tuple containing the start and end indices for the first match in the string let result = regex.captures(string); let (start, end) = match result { Some((s, e)) => (s, e), None => { // ... } }; println!("{}", &string[start, end]); }

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/