Sign in to follow this  
Followers 0
eltorro

nested reg exp.

3 posts in this topic

#1 ·  Posted (edited)

I'm trying to extract a number following some text using regular expressions

#include <Array.au3>
;some text from a webpage
$test = "Server: Apache/1.3.33 (Unix) PHP/5.0.4 mod_perl/1.29"&@crlf
$test &= "Connection: close"&@crlf
$test &= "Content-Type: text/html"&@crlf
$test &= @crlf
$test &="<HTML><HEAD><TITLE>UPDATEDNS</TITLE></HEAD><BODY>" &@crlf
$test &="<!-- DDNS_Response_Code=101 -->" &@crlf
$test &="Status Code: <B>101</B><BR>" &@crlf
$test &="Successful Update.<BR>" &@crlf

msgbox(0,"Test Text",$test)

;find number after "DDNS_Response_Code="
;find non capturing group and capturing group
$pattern ="((?:DDNS_Response_Code=)[0-9]+)"

$result = StringRegExp($test,$pattern,1)

_ArrayDisplay($result,"Results")

The return value is "DDNS_Response_Code=101".

Shouldn't it be "101"?

By the way I am using beta 101. Kinda weird huh?

Edited by eltorro

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

$pattern ="((?:DDNS_Response_Code=)([0-9]+))"

Edit:

And this if you want it to be [1] to return the right option.

$pattern ="((DDNS_Response_Code=)([0-9]*))"

Edited by SmOke_N

[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

Thanks for the help. Sorry it took so long to reply back.

$pattern = "DDNS_Response_Code=(\d+)" also works but I would rather use grouping.

Gotta learn more on regexp.

Thanks,

eltorro

Share this post


Link to post
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
Sign in to follow this  
Followers 0