Description
This Regex will do the following:
- Match all numeric strings like 2, 3977, 432, 5 ..
- Match all Ranges of numeric strings like 2-4, 553-999, 1234-9876
- Match all valid Roman Numerals in the range of 1-4000
- returns an array of only these values and no additional capture groups
The Regex
\b(?:\d+(?:-\d+)?|(?=[MCDLXVI]+\b)M{0,4}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|V?I{0,3}))\b
Note this is just a raw regex, for many languages like Java you'll need to replace the \
with \\
to get it to work correctly.
Explanation

NODE EXPLANATION
----------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
\d+ digits (0-9) (1 or more times (matching
the most amount possible))
----------------------------------------------------------------------
(?: group, but do not capture (optional
(matching the most amount possible)):
----------------------------------------------------------------------
- '-'
----------------------------------------------------------------------
\d+ digits (0-9) (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
)? end of grouping
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------
[MCDLXVI]+ any character of: 'M', 'C', 'D', 'L',
'X', 'V', 'I' (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
\b the boundary between a word char (\w)
and something that is not a word char
----------------------------------------------------------------------
) end of look-ahead
----------------------------------------------------------------------
M{0,4} 'M' (between 0 and 4 times (matching the
most amount possible))
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
CM 'CM'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
CD 'CD'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
D? 'D' (optional (matching the most
amount possible))
----------------------------------------------------------------------
C{0,3} 'C' (between 0 and 3 times (matching
the most amount possible))
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
XC 'XC'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
XL 'XL'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
L? 'L' (optional (matching the most
amount possible))
----------------------------------------------------------------------
X{0,3} 'X' (between 0 and 3 times (matching
the most amount possible))
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
(?: group, but do not capture:
----------------------------------------------------------------------
IX 'IX'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
IV 'IV'
----------------------------------------------------------------------
| OR
----------------------------------------------------------------------
V? 'V' (optional (matching the most
amount possible))
----------------------------------------------------------------------
I{0,3} 'I' (between 0 and 3 times (matching
the most amount possible))
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
----------------------------------------------------------------------
Examples
Live Demo
http://fiddle.re/pvjzra
Sample Text
Adidas, 45-46 Nike, 25 shoes, phone, keyboard, 1-2, 4-5, 7, 9, 12, 13, 32, 35, V, VI, IX
Java Code Example
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class Module1{
public static void main(String[] asd){
String sourcestring = "Adidas, 45-46 Nike, 25 shoes, phone, keyboard, 1-2, 4-5, 7, 9, 12, 13, 32, 35, V, VI, IX";
Pattern re = Pattern.compile("\\b(?:\\d+(?:-\\d+)?|(?=[MCDLXVI]+\\b)M{0,4}(?:CM|CD|D?C{0,3})(?:XC|XL|L?X{0,3})(?:IX|IV|V?I{0,3}))\\b",Pattern.CASE_INSENSITIVE );
Matcher m = re.matcher(sourcestring);
int mIdx = 0;
while (m.find()){
for( int groupIdx = 0; groupIdx < m.groupCount()+1; groupIdx++ ){
System.out.println( "[" + mIdx + "][" + groupIdx + "] = " + m.group(groupIdx));
}
mIdx++;
}
}
}
Matched Array
$matches Array:
(
[0] => Array
(
[0] => 45-46
[1] => 25
[2] => 1-2
[3] => 4-5
[4] => 7
[5] => 9
[6] => 12
[7] => 13
[8] => 32
[9] => 35
[10] => V
[11] => VI
[12] => IX
)
)