Summary
This regex assumes that your source numbers are 4 digit strings. It will find instances where the first comma delimited number is numerically larger than the second number.
As written this regex assumes that you're using the "x" flag which ignores white space or line breaks.
Regex
^(?=\d{4},\d{4}(?:\D|\Z))(?:(?:
[9]\d*,[012345678]\d*|
[89]\d*,[01234567]\d*|
[789]\d*,[0123456]\d*|
[6789]\d*,[012345]\d*|
[56789]\d*,[01234]\d*|
[456789]\d*,[0123]\d*|
[3456789]\d*,[012]\d*|
[23456789]\d*,[01]\d*|
[123456789]\d*,[0]\d*
)|
(?<a>\d{1})(?:
[9]\d*,\k<a>[012345678]\d*|
[89]\d*,\k<a>[01234567]\d*|
[789]\d*,\k<a>[0123456]\d*|
[6789]\d*,\k<a>[012345]\d*|
[56789]\d*,\k<a>[01234]\d*|
[456789]\d*,\k<a>[0123]\d*|
[3456789]\d*,\k<a>[012]\d*|
[23456789]\d*,\k<a>[01]\d*|
[123456789]\d*,\k<a>[0]\d*
)|
(?<b>\d{2})(?:
[9]\d*,\k<b>[012345678]\d*|
[89]\d*,\k<b>[01234567]\d*|
[789]\d*,\k<b>[0123456]\d*|
[6789]\d*,\k<b>[012345]\d*|
[56789]\d*,\k<b>[01234]\d*|
[456789]\d*,\k<b>[0123]\d*|
[3456789]\d*,\k<b>[012]\d*|
[23456789]\d*,\k<b>[01]\d*|
[123456789]\d*,\k<b>[0]\d*
)|
(?<c>\d{3})(?:
[9]\d*,\k<c>[012345678]\d*|
[89]\d*,\k<c>[01234567]\d*|
[789]\d*,\k<c>[0123456]\d*|
[6789]\d*,\k<c>[012345]\d*|
[56789]\d*,\k<c>[01234]\d*|
[456789]\d*,\k<c>[0123]\d*|
[3456789]\d*,\k<c>[012]\d*|
[23456789]\d*,\k<c>[01]\d*|
[123456789]\d*,\k<c>[0]\d*
))
Example
http://www.rubular.com/r/XjBNBQIzGP
Sample text
Born,Died
1852,1891
1862,1862
1902,1785
1111,1111
1111,1110
2222,2202
3333,3033
4444,0444
123,456
1234,567
123,4567
456,123
4567,123
456,1234
4567,1234
Sample capture
[0][0] = 1902,1785
[0][a] = 1
[0][b] =
[0][c] =
[1][0] = 1111,1110
[1][a] =
[1][b] =
[1][c] = 111
[2][0] = 2222,2202
[2][a] =
[2][b] = 22
[2][c] =
[3][0] = 3333,3033
[3][a] = 3
[3][b] =
[3][c] =
[4][0] = 4444,0444
[4][a] =
[4][b] =
[4][c] =
[5][0] = 4567,1234
[5][a] =
[5][b] =
[5][c] =
Short Explanation
The beginning of the regex has a lookahead to validate that we do in fact have two 4 digit numbers.
The four blocks of code test each position to validate if one digit is larger than the other. The second, third, and fourth blocks contain a named backreference (a, b, c respectively). This backreference insures the leading numbers are identical.
More Detailed Explanation
NODE EXPLANATION
----------------------------------------------------------------------
^ the beginning of a "line"
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
\d{4} digits (0-9) (4 times)
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
\d{4} digits (0-9) (4 times)
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
\D non-digits (all but 0-9)
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
\Z before an optional \n, and the end of
the string
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
[9] any character of: '9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[012345678] any character of: '0', '1', '2', '3',
'4', '5', '6', '7', '8'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[89] any character of: '8', '9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[01234567] any character of: '0', '1', '2', '3',
'4', '5', '6', '7'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[789] any character of: '7', '8', '9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[0123456] any character of: '0', '1', '2', '3',
'4', '5', '6'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[6789] any character of: '6', '7', '8', '9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[012345] any character of: '0', '1', '2', '3',
'4', '5'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[56789] any character of: '5', '6', '7', '8',
'9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[01234] any character of: '0', '1', '2', '3',
'4'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[456789] any character of: '4', '5', '6', '7',
'8', '9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[0123] any character of: '0', '1', '2', '3'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[3456789] any character of: '3', '4', '5', '6',
'7', '8', '9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[012] any character of: '0', '1', '2'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[23456789] any character of: '2', '3', '4', '5',
'6', '7', '8', '9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[01] any character of: '0', '1'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
[123456789] any character of: '1', '2', '3', '4',
'5', '6', '7', '8', '9'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
, ','
----------------------------------------------------------------------
[0] any character of: '0'
----------------------------------------------------------------------
\d* digits (0-9) (0 or more times
(matching the most amount possible))
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
) end of grouping