re = /(?>^|\s+|\W)
(
(?>[a-z]\d*|\d+[a-z]?
(?>\(
([a-z]\d*|\d+[a-z]?)
\)[a-z]?
)?)
(?>\.(?>[a-z]|\d+[a-z]?))*
|
(?>M{0,4}(?>CM|CD|D?C{0,3})(?>XC|XL|L?X{0,3})(?>IX|IV|V?I{0,3}))
)
(?>\s+|\W|$)/mix
str = 'Appendix 1
6.48
CP 198
3.2.4 G
2
1.
B.
Appendix 1
Annex A
4A.10.1 and 4A.15
4A.21.10
Annex ii
A)
SECTION IV
52.19A
PRACTICE DIRECTION 83—
RSC ORDER 109
Rule 4
ADMINISTRATIVE COURT GUIDANCE
PRACTICE STATEMENT
THE PROTOCOL
C.6
Draft modules
CIS11:
Appendix 13(2)e
2002 no.
(a)
L7.3.1.R
(iii)
'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html