tom13 Posted November 15, 2007 Posted November 15, 2007 Hey, I'm using the function _StringBetween to get a string between 2 strings (duh..) But now I have the following: _StringBetween($str, '<p class=*anything*>', '</p>') I want xxx in class=xxx to be anything, like a wildcard, so it would return anything thats between <p class=***anything***> and </p>, I tried things like '<p class=' & * & '>' but I guess it's quite obvious that that won't work I hope you understand what I mean. Thanks in advance.
tom13 Posted November 15, 2007 Author Posted November 15, 2007 Learn StringRegExp. Will do the job.It will do this individual job pretty easily yes, but I just made that up as an example so you would understand what I mean. There is a function called _StringBetween and it's meant to get a string that's between 2 strings which is just what I want to do. Now can anyone help me with adding something like wildcards to the _StringBetween function?
Nahuel Posted November 15, 2007 Posted November 15, 2007 I highly doubt you can use wildcards in _StringBetween(). It's useless, that's what StringRegExp is for. $MyString=StringRegExp("<p class=*anything*>Hello lolz</p>",'(?i)<p class=(.*?)>(.*?)</p>',1) MsgBox(0,"",$MyString[1]) $MyString=StringRegExp("<p class='Hi mom, I'm on tv'>Hello lolz</p>",'(?i)<p class=(.*?)>(.*?)</p>',1) MsgBox(0,"",$MyString[1])
tom13 Posted November 15, 2007 Author Posted November 15, 2007 I highly doubt you can use wildcards in _StringBetween(). It's useless, that's what StringRegExp is for. $MyString=StringRegExp("<p class=*anything*>Hello lolz</p>",'(?i)<p class=(.*?)>(.*?)</p>',1) MsgBox(0,"",$MyString[1]) $MyString=StringRegExp("<p class='Hi mom, I'm on tv'>Hello lolz</p>",'(?i)<p class=(.*?)>(.*?)</p>',1) MsgBox(0,"",$MyString[1]) hmm okay, I have no idea how those regular expressions for autoit work though like in your example: (.*?)>(.*?) can't find it in the helpfile either
tom13 Posted November 15, 2007 Author Posted November 15, 2007 hmm okay, I have no idea how those regular expressions for autoit work though like in your example: (.*?)>(.*?) can't find it in the helpfile either Okay, So I got this string: <p> <span class="location">ZOETERMEER - </span> De Nederlandse pluimveesector neemt geen extra maatregelen nu wordt onderzocht of de uitbraak van vogelgriep in Engeland daar wellicht via een Nederlandse transporteur is beland. <a href="http://www.dvhn.nl/nieuws/nederland/article2720201.ece?secId=26">Meer...</a> </p> Now I want to get this piece of the string: De Nederlandse pluimveesector neemt geen extra maatregelen nu wordt onderzocht of de uitbraak van vogelgriep in Engeland daar wellicht via een Nederlandse transporteur is beland. Anyone knows how? I don't because there are newlines (enter) and somehow it doesn't seem to work
Moderators SmOke_N Posted November 15, 2007 Moderators Posted November 15, 2007 #include <Array.au3> #include <String.au3> $sString = ClipGet();I copied the string here from firefox, you'd replace ClipGet() with however you got the string ;StringBetween, no regexp method $aArray = _StringBetween($sString, "/span>" & @CRLF, @CRLF & "<a href") _ArrayDisplay($aArray) ;RegExp Method $aArray = StringRegExp($sString, "\/span\>.+?\n*(.+?)\r*\n*\<a", 3) _ArrayDisplay($aArray) 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.
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