re = /^(\+ *|- *)?((?!0+)\d*?|(?!0{2,})\d*?\.(?!0+)\d*?)('|")$|^(\+ *|- *)? *(?!0+)\d+?' *-? *(\d+?|\d*?\.\d*?)"$|^((\+ *|- *)?((?!0+)|0 )\d*? *(?!0+)\d+?\/(?!0+)\d+?('|"))$/m
str = ' -
+
- x 20\'-4"
+ 20\'
- 20\'
20\'3"
20\'-3"
20\' - 40"
-20\'-20"
20\'00"
20.45"
20.45\'
00.45\'
00.45"
00"
00\'
+20\' - 0.45"
20\' - .45"
.20\'-4"
0.30\'-4"
20\'
20\'P
20"
20"P
0.20\'
.20\'
a\'
b"
- 20 1/2\'
+ 20 22/128"
20 0/2"
20 00/12\'
-1/2"
+ 1/2\'
0/2"
00/22"
+ 01/2"
23 00/30\'
23 12/03\'
23 02/20"
0 2/3\'
00 2/3\'
- 11 2/3\'
2 22\'
2 22/03\'
2 3/2
23 00/30
23 12/03
23 02/20
23/34"
23/23.4"
asf sf"
'
# 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