Jump to content
Sign in to follow this  

StringRegExp that I don't understand

Recommended Posts

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)
    If Not StringRegExp($String,"^1?$|^(11+?)\1+$") Then
        Return 1
        Return 0
Edited by Paulie

Share this post

Link to post
Share on other sites

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.


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  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...