Skip to content Skip to sidebar Skip to footer

Set Together Letters And Numbers That Are Ordinal Numbers

The purpose is to remove the space between the numbers and ordinal number abbreviation (st,rd,th,nd). For instance, the following numbers and abbreviations should be together to f

Solution 1:

You might add another part to the positive lookahead to assert what follows is a word character except an underscore or digit or assert the end of the string in case it is the last occurrence:

(?<=[0-9])\s+(?=(?:st|[rn]d|th)(?: [^\W\d_]|$))

Regex demo

Note that you can omit the + after the positive lookbehind and you might shorten the alternation to [rn]d

Post a Comment for "Set Together Letters And Numbers That Are Ordinal Numbers"