Jump to content

Recommended Posts

Posted


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

Capture.JPG

Posted
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

Posted
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

 

Posted

@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])

 

Posted (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 by mikell
Posted
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 :)

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...