Check if string starts with regex in ruby to match "[NATURAL NUMBER]"
<p>Suppose I have a following strings:</p>

<pre><code>str1 = "[1] : blah blah blah"
str2 = "[2] : Something"
str3 = "Nothing"
</code></pre>

<p>I wrote a method <code>foo(str)</code> that takes a string as parameter and should return true if the string starts with "[DIGIT]" where digit can be any natural number (1,2,3,4...). So <code>str1</code> and <code>str2</code> should return true. <code>str3</code> should return false.</p>

<p>I can't figure out the regular expression to match <code>"[DIGIT]"</code>. <code>/[[\d]]/</code> was the best I could come up with, which doesn't work and only matches <code>"N]"</code>, misses the starting bracket. Try it <a href="https://www.regex101.com/r/xI4cH4/1" rel="nofollow">here</a>.</p>

<p>Currently the method looks like this:</p>

<pre><code>def foo(str)
  str =~ /[[\d]]/
end
</code></pre>