(:(\*|\?|\w)*:)(..*)(::)(.*\b)(\s*\;.*)?
Really I want to isolate the trigger string and the replacement text. I'm working with single lines of text, so no need to worry about newline characters. I can't just capture everything after "::" because I would erroneously capture any comment.
Presumably the rule for a comment is, <one or more white spaces><semicolon><zero or more of any other printable characters> And the whole part should be optional (not every hotstring has a comment).
Here is my subpattern: (\s*\;.*)? The question mark should make it optional, yes? I tried enclosing that whole part in extra parenths, but no joy.
Thoughts?
test code:
Code: Select all
#SingleInstance, Force
; AHK v1.
varMain =
(
::aaa::blah ;comment
::bbb::blah
:T:ccc::Biz ;;;;;; :unreachable
::aaa::blua
:*:cc::Wap ; makes above unreachable
::ddd::bluab
::eee::Boo
:B0C:ccc::Biz ; 101 numbers in my comment!!!!
::ccc::Biz
::fff::blah
::ggg::Foo ;unreachable
::eee::Bang
:*B0:gg::Bar ; makes above unreachable
)
;~ regex := "(:(\*|\?|\w)*:)(..*)(::)(.*\b)(\s*\;+.*)" ; works if comment present... But no comment = no match
;~ regex := "(:(\*|\?|\w)*:)(..*)(::)(.*\b)(\s*\;.*)" ; works, but comment is not optional.
regex := "(:(\*|\?|\w)*:)(..*)(::)(.*\b)(\s*\;.*)?" ; comment is captured with replacement text.
;~ OutArrays
;~ 1 = :*:
;~ 3 = trigger
;~ 5 = expansion
;~ 6 = comment
Loop, parse, varMain, `n, `r ; Check contents line-by-line.
{
If RegExMatch(A_LoopField, regex, result)
MsgBox % "loop " A_Index " item:`n" A_LoopField "`n`n1 " result1 "`n 2 " result2 "`n 3 " result3 " `n 4 " result4 " `n 5 |" result5 "| `n 6 " result6 "`nall " result
else
MsgBox % "loop " A_Index " item:`n" A_LoopField "`n`nNO MATCH"
}
Esc::ExitApp