JavaScript的正则表达式表示法有什么问题? [英] What's wrong with JavaScript's regular expression notation?

查看:147
本文介绍了JavaScript的正则表达式表示法有什么问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在阅读道格拉斯·克罗克福德的网页, JavaScript:世界上最容易被误解的编程语言 ,我忍不住注意到,在设计错误下,他提到了字面正则表达式的符号。究竟他在说什么? JavaScript的正则表达式表示法有什么问题?为什么?

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?

推荐答案

可能与它强制你逃脱的事实有关 / 字符,也许他想要一个更独特的字符用作表示法。

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 // 无效,而 / test\ // 是有效的正则表达式。

/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/#';

其中符号用于表示。

这篇关于JavaScript的正则表达式表示法有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆