Jump to content
Sign in to follow this  
lordsocke

Stringregex between pattern´s

Recommended Posts

lordsocke

Hey there,

I´m struggling around for an hour now to figure out, how to cut a simple string between 2 words in a google response. 

It looks like this:

"description": "Im a string and I don´t know how long I can be!",
          "boundingPoly": {

I want to use a Stringrex. My bad try looks like this: 

$aResult = StringRegExp ($sOutput,"(?i)(?s)(\Q) description(.*?) boundingPoly(\E)",3)

But this seems to be on a totaly wrong way. Thanks for everybody!

Edited by lordsocke

Share this post


Link to post
Share on other sites
iamtheky
#include<string.au3>

$str = '"description": "Im a string and I don´t know how long I can be!",' & _
          '"boundingPoly": {'

$s1 = '"description":'
$s2 = ',"boundingPoly"'

msgbox(0 , '' , _StringBetween($str , $s1 , $s2)[0])

also, probably just this for the regex, but you need to clarify whether the quotes appear as they do in the question, or if they appear like the one in your regex wrapping description and boundingpoly (as i assumed in the above answer)

$str = 'description: "Im a string and I don´t know how long I can be!",' & _
          'boundingPoly: {'

msgbox(0, '' , StringRegExp ($str,"description:(.*?),boundingPoly",3)[0])

 

Edited by iamtheky

,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

Share this post


Link to post
Share on other sites
mikell

May I add, better like this

$res = StringRegExp ($str,"description:(.*?),boundingPoly",3)
If IsArray($res) Then  msgbox(0, '' , $res[0])

So if for any reason the regex fails it will not cause fatal error, script crash and frustrated user

Share this post


Link to post
Share on other sites
lordsocke

looks pretty, thanks for you both! I´m just to retarded for this

Share this post


Link to post
Share on other sites
iamtheky
7 hours ago, mikell said:

better like this

if better means 'in a fashion that takes a penalty to accommodate unsanitized input....'   :ninja:

*you really should probably write it that way and not nest things that can explode.


,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-.
|(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/
(_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_)
| | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) (
| | | | |)| | \ / | | | | | |)| | `--. | |) \ | |
`-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_|
'-' '-' (__) (__) (_) (__)

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  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.