lordsocke Posted March 22, 2018 Share Posted March 22, 2018 (edited) 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 March 22, 2018 by lordsocke Link to comment Share on other sites More sharing options...
iamtheky Posted March 22, 2018 Share Posted March 22, 2018 (edited) #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 March 22, 2018 by iamtheky ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) Link to comment Share on other sites More sharing options...
mikell Posted March 22, 2018 Share Posted March 22, 2018 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 Link to comment Share on other sites More sharing options...
lordsocke Posted March 22, 2018 Author Share Posted March 22, 2018 looks pretty, thanks for you both! I´m just to retarded for this Link to comment Share on other sites More sharing options...
iamtheky Posted March 22, 2018 Share Posted March 22, 2018 7 hours ago, mikell said: better like this if better means 'in a fashion that takes a penalty to accommodate unsanitized input....' *you really should probably write it that way and not nest things that can explode. ,-. .--. ________ .-. .-. ,---. ,-. .-. .-. .-. |(| / /\ \ |\ /| |__ __||| | | || .-' | |/ / \ \_/ )/ (_) / /__\ \ |(\ / | )| | | `-' | | `-. | | / __ \ (_) | | | __ | (_)\/ | (_) | | .-. | | .-' | | \ |__| ) ( | | | | |)| | \ / | | | | | |)| | `--. | |) \ | | `-' |_| (_) | |\/| | `-' /( (_)/( __.' |((_)-' /(_| '-' '-' (__) (__) (_) (__) 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