Question: I have my table named sup\_mon:

```
m_id
1
2
3
4
5

```

lets assume that this post array has 1,2,3 values.

```
$m_id = $_POST['m_id'][$_POST['m_id']];

```

How can i select the m\_id from array post which has the value of m\_id[1],m\_id[2],m\_id[3] ?

like:

```
   m_id
    1
    2
    3

```

Answer: 
A regex isn't the best solution to this problem. The easiest way to cover all the possibilities is to use [`Kernel#Float`](https://ruby-doc.org/core/Kernel.html#method-i-Float) to try to convert the string to a `Float` and then catch the exception:

```
def float?(str)
  !!Float(str)
rescue ArgumentError
  false
end

```

That will cover leading signs (`'+2.18'`, `-3.14`), ignore leading and trailing whitespace, and even handle scientific notation for floats. One hole in just using `Kernel#Float` is that it won't understand `'NaN'` as a `Float` even though `Float::NAN.to_s == 'NaN'` is true, if you want to consider `'NaN'` to be a `Float` then you could do something like this:

```
def float?(str)
  str.strip == 'NaN' || !!Float(str)
rescue ArgumentError
  false
end

```

Similarly for `Float::INFINITY`/`'Infinity'` and `-Float::INFINITY`/`'-Infinity'`.

There's also [`Kernel#Integer`](https://ruby-doc.org/core/Kernel.html#method-i-Integer) if you want to check integers separately.
You want a single regex that matches both integers and floats?

```
/\A[-+]?\d+(\.\d+)?\z/

```

This matches a series of digits (at least one), optionally followed by a dot and another series of digits.