# Determine if a string is numeric

There is the the *String.looks\_like\_number* method, which returns true when a given strings looks like a number:

```ruby
say "0.1E-5".looks_like_number       #=> true
```

Alternatively, we can use regular expressions to determine this:

```ruby
func is_numeric(s) {
    (s ~~ /^[+-]?+(?=\.?[0-9])[0-9_]*+(?:\.[0-9_]++)?(?:[Ee](?:[+-]?+[0-9_]+))?\z/) ||
    (s ~~ /^0(?:b[10_]*|x[0-9A-Fa-f_]*|[0-9_]+\b)\z/)
}
```

Sample:

```ruby
var strings = %w(0 0.0 -123 abc 0x10 0xABC 123a -123e3 0.1E-5 50e);
for str in strings {
    say ("%9s => %s" % (str, is_numeric(str)))
}
```

#### Output:

```
        0 => true
      0.0 => true
     -123 => true
      abc => false
     0x10 => true
    0xABC => true
     123a => false
   -123e3 => true
   0.1E-5 => true
      50e => false
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://trizen.gitbook.io/sidef-lang/programming_tasks/d/determine_if_a_string_is_numeric.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
