# coding=utf8
# the above tag defines encoding for this document and is for Python 2.x compatibility
import re
regex = r"(.*?)\"(\w+)\"\s+\"([\w| .\/\\%]+)\""
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"
" }")
matches = re.search(regex, test_str, re.MULTILINE | re.DOTALL)
if matches:
print ("Match was found at {start}-{end}: {match}".format(start = matches.start(), end = matches.end(), match = matches.group()))
for groupNum in range(0, len(matches.groups())):
groupNum = groupNum + 1
print ("Group {groupNum} found at {start}-{end}: {group}".format(groupNum = groupNum, start = matches.start(groupNum), end = matches.end(groupNum), group = matches.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