OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

regular expression in browser console not returning the expected result [duplicate]

  • Thread starter Thread starter StCyr
  • Start date Start date
S

StCyr

Guest
I don't think this question is a duplicate. The question I'm asking here relates to the behaviour of the (Firefox) browser's JavaScript console.

I'm well aware of the strangeness of this 'g' flag in a JavaScript regular expression, but I don't understand how it affects the result in my browser's JavaScript console.

Let's look closely at the screenshot of my JavaScript console: I create a new RegExp, then directly test it again a string that should match. Though, it doesn't match. Since it's the first test with this RegExp, the 'g' flag shouldn't influence the test yet iinm.

Eventually, you don't have to look at the third line in the screenshot of my JavaScript console.



Does anyone has an explanation why this regular expression test returns false in the browser's console?

enter image description here

In the screenshot above, I create a regex (first line), then test it against a string that should match, but,oddly enough, the test returns false (second line).

What's strange is that the test returns "true" as long as I don't press "Enter" (third line).

<p>I don't think this question is a duplicate. The question I'm asking here relates to the behaviour of the (Firefox) browser's JavaScript console.</p>
<p>I'm well aware of the strangeness of this 'g' flag in a JavaScript regular expression, but I don't understand how it affects the result in my browser's JavaScript console.</p>
<p>Let's look closely at the screenshot of my JavaScript console: I create a new RegExp, then directly test it again a string that should match. Though, it doesn't match. Since it's the first test with this RegExp, the 'g' flag shouldn't influence the test yet iinm.</p>
<p>Eventually, you don't have to look at the third line in the screenshot of my JavaScript console.</p>
<hr />
<p>Does anyone has an explanation why this regular expression test returns false in the browser's console?</p>
<p><a href="https://i.sstatic.net/iVer6HXj.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iVer6HXj.png" alt="enter image description here" /></a></p>
<p>In the screenshot above, I create a regex (first line), then test it against a string that should match, but,oddly enough, the test returns false (second line).</p>
<p>What's strange is that the test returns "true" as long as I don't press "Enter" (third line).</p>
 

Latest posts

Top