Jump to content

Autoit Regrex How to get string after string.


Thy
 Share

Recommended Posts


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

Link to comment
Share on other sites

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

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

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

 

Link to comment
Share on other sites

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 by Deye
Link to comment
Share on other sites

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

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
 Share

  • Recently Browsing   0 members

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