#include <MsgBoxConstants.au3> ; to declare the Constants of MsgBox
Local $sRegex = "(?m)^([ ]{6})(- )((?!name)\w+[:](?:[ ]*(?=\n\1[ ]{4}\S)|[ ]*\S.+))((?:\n\1[ ]{2}.+)*?)(?:\n(\1[ ]{2})(name[ ]*[:])((?:[ ]*(?![>|])\S.+\b)|(?:(?:[ ]*[>|])?\n\5[ ]+.+)*))[ ]*$"
Local $sString = "// YAML Textmate grammar name property hoister" & @CRLF & _
"// Moves a later `name` key value pair in multi value block definition to the " & @CRLF & _
"// top of its " & @CRLF & _
"//" & @CRLF & _
"// # Notes" & @CRLF & _
"// - Indent size is assumed to be 2." & @CRLF & _
"// - Indent level of names being hoisted is controlled by capture group $1," & @CRLF & _
"// which is later referenced by $5, the indent level of all other properties" & @CRLF & _
"// - Other properties can be hoisted by replacing the two instances of `name`" & @CRLF & _
"// in the pattern. A couple inputs for simple nested, folded, and literal values " & @CRLF & _
"// (immediately after these notes) seem to work." & @CRLF & _
"// - Syntax level comments in captures will probably need to be rearranged after " & @CRLF & _
"// applying this, and worst case (especially comments lower indents) break matching" & @CRLF & _
"" & @CRLF & _
" - match: '\s*(\,)\s*'" & @CRLF & _
" name:" & @CRLF & _
" 'Testing': Regex101.Debug.Nested.Name" & @CRLF & _
" - match: '\s*(\,)\s*'" & @CRLF & _
" name:" & @CRLF & _
" 'Testing': Regex101.Debug.Nested.Name.TrailingWhitespace " & @CRLF & _
" - match: '\s*(\,)\s*'" & @CRLF & _
" # Comment" & @CRLF & _
" name:" & @CRLF & _
" 'Testing': Regex101.Debug.Nested.Name.TrailingWhitespace " & @CRLF & _
" - match: '\s*(\,)\s*'" & @CRLF & _
" name: >" & @CRLF & _
" Wow this is a long name?" & @CRLF & _
" kind of sus" & @CRLF & _
" - match: '\s*(\,)\s*'" & @CRLF & _
" name: |" & @CRLF & _
" sus2" & @CRLF & _
" - name: meta.selector.stylus" & @CRLF & _
" match: '\s*(\,)\s*'" & @CRLF & _
" - match: \*" & @CRLF & _
" name: meta.selector.stylus " & @CRLF & _
" - match: '\s*(\&)([a-zA-Z0-9_-]+)\s*'" & @CRLF & _
" captures:" & @CRLF & _
" '2':" & @CRLF & _
" name: entity.other.attribute-name.parent-selector-suffix.stylus" & @CRLF & _
" name: meta.selector.stylus" & @CRLF & _
" - match: \s*(\&)\s*" & @CRLF & _
" name: meta.selector.stylus" & @CRLF & _
" - captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" match: '(\.)[a-zA-Z0-9_-]+'" & @CRLF & _
" name: entity.other.attribute-name.class.css" & @CRLF & _
" - captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" match: '(#)[a-zA-Z][a-zA-Z0-9_-]*'" & @CRLF & _
" name: entity.other.attribute-name.id.css" & @CRLF & _
" - captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" match: >-" & @CRLF & _
" (:+)(after|before|content|first-letter|first-line|host|(-(moz|webkit|ms)-)?selection)\b" & @CRLF & _
" name: entity.other.attribute-name.pseudo-element.css" & @CRLF & _
" - captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" match: >-" & @CRLF & _
" (:)((first|last)-child|(first|last|only)-of-type|empty|root|target|first|left|right)\b" & @CRLF & _
" name: entity.other.attribute-name.pseudo-class.css" & @CRLF & _
" - captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" match: >-" & @CRLF & _
" (:)(checked|enabled|default|disabled|indeterminate|invalid|optional|required|valid)\b" & @CRLF & _
" name: entity.other.attribute-name.pseudo-class.ui-state.css" & @CRLF & _
" - begin: '((:)not)(\()'" & @CRLF & _
" beginCaptures:" & @CRLF & _
" '1':" & @CRLF & _
" name: entity.other.attribute-name.pseudo-class.css" & @CRLF & _
" '2':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" '3':" & @CRLF & _
" name: punctuation.section.function.css" & @CRLF & _
" end: \)" & @CRLF & _
" endCaptures:" & @CRLF & _
" '0':" & @CRLF & _
" name: punctuation.section.function.css" & @CRLF & _
" patterns:" & @CRLF & _
" - include: '#selector'" & @CRLF & _
" - captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: entity.other.attribute-name.pseudo-class.css" & @CRLF & _
" '2':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" '3':" & @CRLF & _
" name: punctuation.section.function.css" & @CRLF & _
" '4':" & @CRLF & _
" name: constant.numeric.css" & @CRLF & _
" '5':" & @CRLF & _
" name: punctuation.section.function.css" & @CRLF & _
" match: >-" & @CRLF & _
" ((:)nth-(?:(?:last-)?child|(?:last-)?of-type))(\()(\-?(?:\d+n?|n)(?:\+\d+)?|even|odd)(\))" & @CRLF & _
" - match: '((:)dir)\s*(?:(\()(ltr|rtl)?(\)))?'" & @CRLF & _
" captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: entity.other.attribute-name.pseudo-class.css" & @CRLF & _
" '2':" & @CRLF & _
" name: puncutation.definition.entity.css" & @CRLF & _
" '3':" & @CRLF & _
" name: punctuation.section.function.css" & @CRLF & _
" '4':" & @CRLF & _
" name: constant.language.css" & @CRLF & _
" '5':" & @CRLF & _
" name: punctuation.section.function.css" & @CRLF & _
" - match: '((:)lang)\s*(?:(\()(\w+(-\w+)?)?(\)))?'" & @CRLF & _
" captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: entity.other.attribute-name.pseudo-class.css" & @CRLF & _
" '2':" & @CRLF & _
" name: puncutation.definition.entity.css" & @CRLF & _
" '3':" & @CRLF & _
" name: punctuation.section.function.css" & @CRLF & _
" '4':" & @CRLF & _
" name: constant.language.css" & @CRLF & _
" '6':" & @CRLF & _
" name: punctuation.section.function.css" & @CRLF & _
" - captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" match: '(:)(active|hover|link|visited|focus)\b'" & @CRLF & _
" name: entity.other.attribute-name.pseudo-class.css" & @CRLF & _
" - captures:" & @CRLF & _
" '1':" & @CRLF & _
" name: punctuation.definition.entity.css" & @CRLF & _
" match: '(::)(shadow)\b'" & @CRLF & _
" name: entity.other.attribute-name.pseudo-class.css"
Local $sSubst = "$1$2$6$7\n$5$3$4"
Local $sResult = StringRegExpReplace($sString, $sRegex, $sSubst)
MsgBox($MB_SYSTEMMODAL, "Result", $sResult)
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 AutoIt, please visit: https://www.autoitscript.com/autoit3/docs/functions/StringRegExp.htm