Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #20871

Re: Regex match

Newsgroups comp.lang.javascript
Subject Re: Regex match
From "Evertjan." <exxjxw.hannivoort@inter.nl.net>
References <61905f9d-bebd-42c7-a474-4d5f3db23bd3@googlegroups.com>
Date 2013-08-05 23:45 +0200
Message-ID <XnsA213F199B82ABeejj99@194.109.133.133> (permalink)

Show all headers | View raw


 wrote on 05 aug 2013 in comp.lang.javascript:

> Succinctly, my question is, why does this provide a match:
> 
>  'D123'.match(/\d+/);  // -> result is ["123"]
> 
> whereas this does not provide a match:
> 
>  'D123'.match(/\d*/)   // -> [""]

Oh, but it DOES provide a match!!!!

The first match of \d* 
is the empty string section in front of the 'D'.

This will explain it to you:

alert( 'D123'.replace(/\d+/,'x') ); // Dx

and

alert( 'D123'.replace(/\d*/,'x') ); // xD123




-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Regex match andrew.perrins@gmail.com - 2013-08-05 14:16 -0700
  Re: Regex match "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2013-08-05 23:45 +0200
  Re: Regex match Ben Bacarisse <ben.usenet@bsb.me.uk> - 2013-08-05 22:45 +0100

csiph-web