SoFunction
Updated on 2025-04-11

VBS regular discrimination prime number (prime number)

Use regular discrimination of prime numbers, which comes from the Internet, gods and man!

Copy the codeThe code is as follows:

Set regex = New RegExp
= "^1?$¦^(11+?)\1+$"
For i = 1 To 100
 If Not (String(i,"1")) Then
   i
 End If
Next

When you see the title, you will definitely be disdainful. Who can’t enumerate prime numbers?

Copy the codeThe code is as follows:

For i = 1 To 100
 For j = 2 To i
  If i Mod j = 0 Then Exit For
 Next
 If j = i Then i
Next

It can be done in just a few lines of code, so simple. Then take a look at the following program!

Copy the codeThe code is as follows:

Set regex = New RegExp
= "^1?$|^(11+?)\1+$"
For i = 1 To 100
 If Not (String(i,"1")) Then
   i
 End If
Next

Use regular expressions to judge prime numbers, god-like characters.

source:
/programming/
/?p=533