Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
Created·2016-01-12 17:37
Flavor·PCRE (Legacy)

/
^(((1)st?|(2)nd?|(3)rd?|([4-9])th?)|(([0-9]*)(1[0-9])th?)|(([0-9]*[02-9])((1)st?|(2)nd?|(3)rd?|([04-9])th?)))$
/
igm
Open regex in editor

Description

a robust pattern to remove ordinal suffixes from numbers, eg. '22nd'->'22'

supports: singles: 1st, 2nd, 3rd, 4th teens: 11th, 12th, 13th, 14th

Submitted by missinglink