Jump to content

RegExp, find smallest match on start string


Recommended Posts

I am trying to run StringRegExp('< No < No < No < Bingo > No > No > No >','<(.*?)>',3), I want it to return " Bingo ", instead it returns " No < No < No < Bingo ". I know that "?" will find the minimum match, but it seems like it only applies to the end string only, is the a way to also apply minimum matching to the start string? Thanks in advance.

Link to comment
Share on other sites

I am trying to run StringRegExp('< No < No < No < Bingo > No > No > No >','<(.*?)>',3), I want it to return " Bingo ", instead it returns " No < No < No < Bingo ". I know that "?" will find the minimum match, but it seems like it only applies to the end string only, is the a way to also apply minimum matching to the start string? Thanks in advance.

I'm no expert, truuuuuuust me, but as i'm learning more and mroe about regex's as i use them so frequently, i downloaded a program called The Regex Coach, it's free, so look it up, it'll help you.

$nOffset = 1
While 1
    $array = StringRegExp('< No < No < No < Bingo > No > No > No >','\<.*\<(.*?)>',1, $nOffset)
    
    If @error = 0 Then
        $nOffset = @extended
    Else
        ExitLoop
    EndIf
    for $i = 0 to UBound($array) - 1
        msgbox(0, "RegExp Test with Option 1 - " & $i, $array[$i])
    Next
WEnd

Give it a try, it finds bingo rather easily. Now, like I said, i'm no expert, in any means, so I may be way wrong :) But, from what I've been told you have to escape <'s and then if you use .* it tells it to find whatever (pretty much ignors anything after that, and your last syntax \<(.*?)> will tell it find what is between the < and the >.

EDIT: Now that I think on it, you could just do this:

.*\<(.*?)>

Since your just looking inside of the brackets

And, if you do indeed have spaces between your text and your brackets you could use:

.*\<\s(.*?)\s>

Which should just return the text one space after the < and one space before the >

Like i said: I AM NO EXPERT I'm sure many on here would correct me, so expect more results if i'm wrong :)

Edited by zackrspv

-_-------__--_-_-____---_-_--_-__-__-_ ^^€ñ†®øÞÿ ë×阮§ wï†høµ† ƒë@®, wï†høµ† †ïmë, @ñd wï†høµ† @ †ïmïdï†ÿ ƒø® !ïƒë. €×阮 ñø†, bµ† ïñ§†ë@d wï†hïñ, ñ@ÿ, †h®øµghøµ† †hë 맧ëñ§ë øƒ !ïƒë.

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...