I was reading Douglas Crockford's web page, JavaScript: The World's Most Misunderstood Programming Language, and I couldn't help but notice that, under Design Errors, he mentions "the notation for literal regular expressions." What exactly is he talking about? What's wrong with JavaScript's notation for regular expressions, and why?
Basically (0+1)* mathes any sequence of ones and zeroes. So, in your example (0+1)*1(0+1)* should match any sequence that has 1. It would not match 000 , but it would match 010 , 1 , 111 etc. (0+1) means 0 OR 1. 1* means any number of ones.
(. *?) matches any character ( . ) any number of times ( * ), as few times as possible to make the regex match ( ? ). You'll get a match on any string, but you'll only capture a blank string because of the question mark.
The JavaScript exception "invalid regular expression flag" occurs when the flags in a regular expression contain any flag that is not one of: g , i , m , s , u , y or d .
The regular expression \s is a predefined character class. It indicates a single whitespace character. Let's review the set of whitespace characters: [ \t\n\x0B\f\r]
Might have to do with the fact that it enforces you to escape /
characters, perhaps he wanted a more unique character to use as the notation.
/test//
is invalid, while /test\//
is a valid regex.
Whereas in some languages you can actually specify the denotion character in a string, eg:
$regex = '#test/#';
Where #
symbols do the denotion.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With