Jump to content
Sign in to follow this  
Paulie

StringRegExp that I don't understand

Recommended Posts

Paulie

I just "Stumbled Upon" this Regular Expression that seems to be able to tell if a number is prime.

I piped it into autoit, and it seems to work!

Unfortunately, due to my limited knowledge of StringRegExp, I find myself unable to understand exactly how it works, and i was wondering if one of the RegExp Gurus here could give me an explanation of the logic behind it.

Func _IsPrime($Integer)
    $String = ""
    For $i = 1 to Number($Integer)
        $String&="1"
    Next
    If Not StringRegExp($String,"^1?$|^(11+?)\1+$") Then
        Return 1
    Else
        Return 0
    EndIf
EndFunc
Edited by Paulie

Share this post


Link to post
Share on other sites
Paulie

I have a feeling that i have managed to fugure at least the vast majority of this one out by myself.

Now that i understand the concept of "Backtracking" it all makes sense.

Thanks

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  

×