Astormooke Posted September 29, 2013 Share Posted September 29, 2013 Hello, I am having some troubles understanding why my Regexp for the following string isnt working Atmosphere byBilly the kid onRadio Radio now my Regexp is: "by(w){1,30} on" without the "" I would like to understand Regexp a lot more ive read the help file and tried reading some articles off of google but still cant quite grasp the concept. I amd trying to get "Billy the kid" as the return value. Any help would be appreciated, Thanks in advance. Link to comment Share on other sites More sharing options...
somdcomputerguy Posted September 29, 2013 Share Posted September 29, 2013 (edited) You could use the _StringBetween and StringStripWS functions.#include <String.au3> Local $sVar = "Atmosphere byBilly the kid onRadio Radio", _ $aArr = _StringBetween($sVar, "by", "on") ConsoleWrite(StringStripWS($aArr[0], 8) & @LF)edit: I added the StringStripWS function.. Edited September 29, 2013 by somdcomputerguy - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Astormooke Posted September 29, 2013 Author Share Posted September 29, 2013 Ok yes I like that solution... However purely as an exercise is there anyway to produce that same output using regex? Link to comment Share on other sites More sharing options...
somdcomputerguy Posted September 29, 2013 Share Posted September 29, 2013 I know there is, there has to be, but my RegEx knowing is weak, that's why I posted the StringBetween solution.. - Bruce /*somdcomputerguy */ If you change the way you look at things, the things you look at change. Link to comment Share on other sites More sharing options...
Solution Malkey Posted September 29, 2013 Solution Share Posted September 29, 2013 Here is an example. #include <Array.au3> Local $sString = "Atmosphere byBilly the kid onRadio Radio" ;Capture all word and horizontal whitespace characters between "by" and " on". Local $aArray = StringRegExp($sString, "by([\h\w]+?) on", 3) _ArrayDisplay($aArray) ;Or ; Replace from beginning of string to "by" and/or Replace from " on" to end of string with nothing,"". Local $sSubString = StringRegExpReplace($sString, "(^.*by)|( on.*$)", "") MsgBox(0, "Results", $sSubString) Link to comment Share on other sites More sharing options...
mikell Posted September 30, 2013 Share Posted September 30, 2013 (edited) An other one (variant of Malkey's #2) Local $sString = "Atmosphere byBilly the kid onRadio Radio" ; replace the whole string by the part between 'by' and ' on' using the backreference $1 Local $sSubString = StringRegExpReplace($sString, "^.*by(.*?) on.*$", "$1") MsgBox(0, "Results", $sSubString) Edited September 30, 2013 by mikell 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