x Did you like it? Well, then please consider making a donation :)

Regex Tag - parsing-text

How to get numbers 1st, 2nd, 3rd, 4th from text

You can use capturing groups to organize and parse an expression. A non-capturing group has the first benefit, but doesn't have the overhead of the second. You can still say a non-capturing group is optional, for example. Say you want to match numeric text, but some numbers could be written as 1st, 2nd, 3rd, 4th... If you want to capture the numeric part, but not the (optional) suffix you can use a non-capturing group. ([0-9]+)(?:st|nd|rd|th)? That will match numbers in the form 1, 2, 3... or in the form 1st, 2nd, 3rd,... but it will only capture the numeric part.

Type: match, Date: 7/12/2015 3:26:19 PMAuthor: stackoverflow