Thy Posted November 12, 2018 Share Posted November 12, 2018 Hello, I am new to Autoit. I have this string: '[2018.11.13-04:07:54]:新的输出:A1 B2 C3 D4 E5 ' I want to get these red characters, they are located right after '新的输出:' and before the end of the string. '[2018.11.13-04:07:54]:新的输出:A1 B2 C3 D4 E5 ' I used to use PHP and I can do this by this simple regex syntax and it works very well exactly like what I expected: '/(?<=新的输出:).*$/' I just want to to same thing in Autoit script $string = "[2018.11.13-04:07:54]:新的输出:A1 B2 C3 D4 E5 "; MsgBox (0,'',$string) $result = StringRegExp($string, '/(?<=新的输出:).*$/', $STR_REGEXPARRAYFULLMATCH) MsgBox (0,'',$result) But it returns nothing. Can you please help me to figure out? Thanks Link to comment Share on other sites More sharing options...
Deye Posted November 12, 2018 Share Posted November 12, 2018 (edited) Thy, welcome to autoitscript forum This seems to do it : MsgBox(0, '', StringRegExp($string, '(?:\w.?\s)+[\w\d].', 3)[0]) Deye Edited November 12, 2018 by Deye Thy 1 Link to comment Share on other sites More sharing options...
Thy Posted November 12, 2018 Author Share Posted November 12, 2018 4 minutes ago, Deye said: Thy, welcome to autoitscript forum This seems to do it : MsgBox(0,'',StringRegExp($string, '(?:\w.?\s)+', 3)[0]) Deye Thank you so much for the reply. I have tested it, it works like a charm!!! But there is a problem is that, what if I have to do Regular expression by using Chinese words which are not latin characters. In this case, I get the error: Subscript used on non-accessible variable Link to comment Share on other sites More sharing options...
Deye Posted November 12, 2018 Share Posted November 12, 2018 1 minute ago, Thy said: I get the error: Subscript used on non-accessible variable show us in what case will it fail ,also try the edited above Deye Thy 1 Link to comment Share on other sites More sharing options...
Thy Posted November 12, 2018 Author Share Posted November 12, 2018 7 minutes ago, Deye said: show us in what case will it fail ,also try the edited above Deye As far as I see, your example get all the value of two grouped characters, separated by spaces; meanwhile I just want to get the value after this '新的输出:' '[2018.11.13-04:07:54]:新的输出:value ' It fails if the string doesn't have that kind of formatting Link to comment Share on other sites More sharing options...
TheXman Posted November 13, 2018 Share Posted November 13, 2018 @Thy Search patterns in AutoIt are not surrounded by "/". #include <Constants.au3> $string = "[2018.11.13-04:07:54]:新的输出:A1 B2 C3 D4 E5 "; MsgBox (0,'',$string) $result = StringRegExp($string, '(?<=新的输出:).*$', $STR_REGEXPARRAYFULLMATCH) MsgBox (0,'',$result[0]) Thy 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman Link to comment Share on other sites More sharing options...
mikell Posted November 13, 2018 Share Posted November 13, 2018 (edited) Deye, To make your expression able to work with Chinese characters you need to enable Unicode mode using (*UCP) BTW the syntax of TheXman's one doesn't need it (because it doesn't use \w) Edited November 13, 2018 by mikell Deye and Thy 2 Link to comment Share on other sites More sharing options...
Deye Posted November 13, 2018 Share Posted November 13, 2018 (edited) Nice, So My last edit will also work on this string reversed .. $str = "[2018.11.13-04:07:54]:新的输出:A1 B2 C3 D4 E5 " $patt = '(*UCP)(?:\w.?\s)+[\w\d].' MsgBox(0, '', '"' & StringRegExp($str, $patt, 3)[0] & '"') $str = StringReverse($str) MsgBox(0, '', '"' & StringRegExp($str, $patt, 3)[0] & '"') Deye Edited November 13, 2018 by Deye Thy 1 Link to comment Share on other sites More sharing options...
Thy Posted November 13, 2018 Author Share Posted November 13, 2018 18 hours ago, TheXman said: @Thy Search patterns in AutoIt are not surrounded by "/". #include <Constants.au3> $string = "[2018.11.13-04:07:54]:新的输出:A1 B2 C3 D4 E5 "; MsgBox (0,'',$string) $result = StringRegExp($string, '(?<=新的输出:).*$', $STR_REGEXPARRAYFULLMATCH) MsgBox (0,'',$result[0]) Oh my God, thank you for showing me, I wasted hours finding other ways meanwhile it was initially almost done @mikell @Deye Thanks again for your help. I am using your regular expression syntax, yes it works well Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now