Jump to content
Sign in to follow this  
tom13

_StringBetween wildcards or "*", "?", "."

Recommended Posts

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 :P

I hope you understand what I mean.

Thanks in advance.

Share this post


Link to post
Share on other sites

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?

Share this post


Link to post
Share on other sites

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])

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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&nbsp;-&nbsp;</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

Share this post


Link to post
Share on other sites

#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.

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  

×
×
  • Create New...