re = /([\d]*)(.|,)[\d](e|E)[\d]+/m
str = 'Valid floating points:
1
+1
-1
65
+65
-65
5.2
5,2
5.225
5,225
985.225
985,225
985.
,225
+5.2
+5,2
+5.225
+5,225
+985.225
+985,225
+985.
+,225
-5.2
-5,2
-5.225
-5,225
-985.225
-985,225
-985.
-,225
5.2E3
5.2e3
+5.2e3
-5.2e3
5,2E3
5,2e3
-5,2e3
+5,2e3
5.2e112
+5.2e112245
-5.2e99999
5,2e112
-5,2e112245
+5,2e99999
5.2e+3
+5.2e+3
-5.2e+3
5,2e-3
-5,2e-3
+5,2e-3
5.e3
5.e+3
+5.e+3
-5.e+3
5,e-3
-5,e-3
+5,e-3
,225e123
+,225e123
-,225e123
.225e123
+.225e123
-.225e123
Not floating points
,
,
,
.
.
.
.e
,e
.e2
,e2
,225e
+,225e
-,225e
.225e
+.225e
-.225e'
# 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