JavaScript Help How do you locate the first occurrence of th

JavaScript Help:

How do you locate the first occurrence of three consecutive digits in a string?

For example: console.log(\"more than you can shake a stick at\".match(/([\\w]+)/g));

This is one was in which you can arrive at an answer, provide an alternative solution.

Solution

In regular expersion \\d represents digit

so we can use /^\\d{3}$/   this regular expresion matches only if string contains 3 digit.

example : 123

/^\\d{3}.*$/   the regular expresion matches string contains first 3 digits and strings may or may not

example :

123asdfas // correct

546 // correct

asdfa34534 // incorrect

JavaScript Help: How do you locate the first occurrence of three consecutive digits in a string? For example: console.log(\

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site