Regular Expressions 101

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
^ (?<born> # BORN part start (?:(?<o>1)|(?<t>2)|(?<h>3)|(?<f>4)|(?<v>5)|(?<s>6)|(?<n>7)|(?<e>8)|(?<i>9)|(?<z>0)) # Thousands (?:(?<o2>1)|(?<t2>2)|(?<h2>3)|(?<f2>4)|(?<v2>5)|(?<s2>6)|(?<n2>7)|(?<e2>8)|(?<i2>9)|(?<z2>0)) # Centuries (?:(?<o3>1)|(?<t3>2)|(?<h3>3)|(?<f3>4)|(?<v3>5)|(?<s3>6)|(?<n3>7)|(?<e3>8)|(?<i3>9)|(?<z3>0)) # Decades (?:(?<o4>1)|(?<t4>2)|(?<h4>3)|(?<f4>4)|(?<v4>5)|(?<s4>6)|(?<n4>7)|(?<e4>8)|(?<i4>9)|(?<z4>0)) # Last digit ) , (?!\k<born>) #Fail if years are identical (?: #1st digit is lower (?:(?(o)0|(?(t)[01]|(?(h)[0-2]|(?(f)[0-3]|(?(v)[0-4]|(?(s)[0-5]|(?(n)[0-6]|(?(e)[0-7]|(?(i)[0-8]|-1)))))))))) \d{3} | #1st digit is lower or identical (?:(?(o)[01]|(?(t)[0-2]|(?(h)[0-3]|(?(f)[0-4]|(?(v)[0-5]|(?(s)[0-6]|(?(n)[0-7]|(?(e)[0-8]|(?(i)[0-9]|-1)))))))))) #and 2nd is lower (?:(?(o2)0|(?(t2)[01]|(?(h2)[0-2]|(?(f2)[0-3]|(?(v2)[0-4]|(?(s2)[0-5]|(?(n2)[0-6]|(?(e2)[0-7]|(?(i2)[0-8]|-1)))))))))) \d{2} | #1st digit is lower or identical (?:(?(o)[01]|(?(t)[0-2]|(?(h)[0-3]|(?(f)[0-4]|(?(v)[0-5]|(?(s)[0-6]|(?(n)[0-7]|(?(e)[0-8]|(?(i)[0-9]|-1)))))))))) #and 2nd is lower or identical (?:(?(o2)[01]|(?(t2)[0-2]|(?(h2)[0-3]|(?(f2)[0-4]|(?(v2)[0-5]|(?(s2)[0-6]|(?(n2)[0-7]|(?(e2)[0-8]|(?(i2)[0-9]|-1)))))))))) #and 3rd is lower (?:(?(o3)0|(?(t3)[01]|(?(h3)[0-2]|(?(f3)[0-3]|(?(v3)[0-4]|(?(s3)[0-5]|(?(n3)[0-6]|(?(e3)[0-7]|(?(i3)[0-8]|-1)))))))))) \d | #1st digit is lower or identical (?:(?(o)[01]|(?(t)[0-2]|(?(h)[0-3]|(?(f)[0-4]|(?(v)[0-5]|(?(s)[0-6]|(?(n)[0-7]|(?(e)[0-8]|(?(i)[0-9]|-1)))))))))) #and 2nd is lower or identical (?:(?(o2)[01]|(?(t2)[0-2]|(?(h2)[0-3]|(?(f2)[0-4]|(?(v2)[0-5]|(?(s2)[0-6]|(?(n2)[0-7]|(?(e2)[0-8]|(?(i2)[0-9]|-1)))))))))) #and 3rd is lower or identical (?:(?(o3)[01]|(?(t3)[0-2]|(?(h3)[0-3]|(?(f3)[0-4]|(?(v3)[0-5]|(?(s3)[0-6]|(?(n3)[0-7]|(?(e3)[0-8]|(?(i3)[0-9]|-1)))))))))) #and 4th is lower (?:(?(o4)0|(?(t4)[01]|(?(h4)[0-2]|(?(f4)[0-3]|(?(v4)[0-4]|(?(s4)[0-5]|(?(n4)[0-6]|(?(e4)[0-7]|(?(i4)[0-8]|-1)))))))))) ) $
/
gmx

Description

Compares two comma separated 4-digit years, and if the first one is greater, a match is returned. AUTHOR: Wiktor Stribizew SO PRofile: http://stackoverflow.com/users/3832970/wiktor-stribi%C5%BCew

Submitted by Wiktor Stribizew - 9 years ago