import re
regex = re.compile(r":.*(\$[\w-]+)", flags=re.MULTILINE)
test_str = (".dabur-india{\n"
" color: $color-brand-group-3-light !important;\n"
" .mmm{\n"
" background: $color-brand-group-2-dark;\n"
" $border-dark: rgba($base-color, 0.88);\n"
" .alert {\n"
" border: 1px solid $border-dark;\n"
" }\n"
" }\n"
"}\n\n"
"$black: #000 !default;\n"
"$border-radius: 0.25rem !default;\n"
"$box-shadow: 0 0.5rem 1rem rgba($black, 0.15) !default;\n\n"
"code {\n"
" border-radius: $border-radius;\n"
" box-shadow: $box-shadow;\n"
"}\n\n"
"@if $dark-theme {\n"
" $primary-color: darken($primary-color, 60%);\n"
" $accent-color: lighten($accent-color, 60%);\n"
"}\n\n"
"$theme-colors: (\n"
" \"success\": #28a745,\n"
" \"info\": #17a2b8,\n"
" \"warning\": #ffc107,\n"
");\n\n"
".alert {\n"
" // Instead of $theme-color-#{warning}\n"
" background-color: map.get($theme-colors, \"warning\");\n"
"}")
matches = regex.finditer(test_str)
for match_num, match in enumerate(matches, start=1):
print(f"Match {match_num} 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