Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
.NET 7.0 (C#)

@"
^(?:(?<Number>)(?<Prime>(?<SmallestFactor>(?<char>.)\<char>+?))(?:\<SmallestFactor>+(?<-Prime>(?=)))?(?!\<char>)(?<-char>)(?(Prime)(?<-SmallestFactor>)(?<-Number>)|(?<Composite-Number>))|(?<Unit>.)|(?<MustUseTheSameCharacter>.+))$|(?<Zero>^$)
"
gm

Description

Description

Inspects lines that contain only a character, let's say c, repeated n times. The name of the matching groups will tell you if n is 0, the unit 1, a prime number, or a composite number.

Alternative

Removing the outermost anchors ^ and $ from the first (and very large) alternate group will do the same but, instead of inspecting per line, it will inspect any repetition of a character (line breaks, obviously, stop repetitions).

^(?: ...... )$|(?<Zero>^$)

to

(?: ...... )|(?<Zero>^$)
Submitted by kevinhp - 10 days ago