2016-06-14 2 views
0

이걸 빨리 설명하려고합니다.AutoHotkey | RegExMatch

RegExMatch를 사용하여 올바른 var를 저장하기 위해 입력해야하는 문자를 파악하는 데 도움이 필요합니다. *SPEC* TEST TEST : !hello

내가 VAR이 원하는 :

RegExMatch(LLine, "(.*) : !hello", Name) 
    SendInput, y 
    sleep, 1000 
    SendInput, Hello %Name1%, how are you?{enter} 

그래서 채팅 출력은 예를 들어 다음과 같이이다 TEST TEST

(.*) 내가 그에게 할 수있는 방법 : !hello

앞에 모든 것을 저장 *SPEC* 부분을 저장하지 않으시겠습니까?

또한 모든 사람이 이름에 *SPEC*을 갖고있는 것은 아닙니다. Spec ofc에없는 경우, 그는 채팅에 표시하지 않을 것입니다.

someones 이름이 "TEST"와 같은 단 하나의 단어 일지라도, 나는 var로 단일 단어를 저장하기를 원합니다.


여러분이 내 뜻을 이해하고 나를 도울 수 있기를 바랍니다. 정말 감사 할 것입니다!

+0

일치 문자열을 regEx 부분으로'regExReplace'를 사용하십시오 – Blauhirn

답변

1

설명

i)^(?:\*spec\*)?\s*([^:]*)\s+:\s+!hello 

Regular expression visualization

I가 i)로 AutoHotkey에 적용되는이 정규 표현식에 대한 플래그 insenstitve 케이스를 사용하고 있습니다.

AutoHotkey에 샘플 코드

InputString := "*SPEC* TEST TEST : !hello" 
RegexMatch(InputString, "i)^(?:\*spec\*)?\s*([^:]*)\s+:\s+!hello", Match) 

strMessage := "InputString = '" . InputString . "'" 
strMessage .= "`nName = '" . Match1 . "'" 
MsgBox, % strMessage 

AutoHotkey를 출력

--------------------------- 
DesktopAutomation.ahk 
--------------------------- 
InputString = '*SPEC* TEST TEST : !hello' 
Name = 'TEST TEST' 
--------------------------- 
OK 
--------------------------- 

라이브 데모

정규식 예 : 사용자가 교체 할 경우 https://regex101.com/r/tP1uI5/1

샘플 텍스트

*SPEC* TEST TEST : !hello 

샘플

MATCH 1 
1. [7-16] `TEST TEST` 

설명

NODE      EXPLANATION 
---------------------------------------------------------------------- 
i)      set case insensitive mode 
---------------------------------------------------------------------- 
^      the beginning of the string 
---------------------------------------------------------------------- 
    (?:      group, but do not capture (optional 
          (matching the most amount possible)): 
---------------------------------------------------------------------- 
    \*      '*' 
---------------------------------------------------------------------- 
    spec      'spec' 
---------------------------------------------------------------------- 
    \*      '*' 
---------------------------------------------------------------------- 
)?      end of grouping 
---------------------------------------------------------------------- 
    \s*      whitespace (\n, \r, \t, \f, and " ") (0 or 
          more times (matching the most amount 
          possible)) 
---------------------------------------------------------------------- 
    (      group and capture to \1: 
---------------------------------------------------------------------- 
    [^:]*     any character except: ':' (0 or more 
          times (matching the most amount 
          possible)) 
---------------------------------------------------------------------- 
)      end of \1 
---------------------------------------------------------------------- 
    \s+      whitespace (\n, \r, \t, \f, and " ") (1 or 
          more times (matching the most amount 
          possible)) 
---------------------------------------------------------------------- 
    :      ':' 
---------------------------------------------------------------------- 
    \s+      whitespace (\n, \r, \t, \f, and " ") (1 or 
          more times (matching the most amount 
          possible)) 
---------------------------------------------------------------------- 
    !hello     '!hello' 
---------------------------------------------------------------------- 
+0

정말 고마워요! 그게 정말 많이 도와 줘요! – user3430374