正则表达式中美元符号的含义 [英] meaning of dollar symbol in regular expression

查看:163
本文介绍了正则表达式中美元符号的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您能帮我以下正则表达式中 $ 的用法是什么;我不知道这有什么用?这是否只是字符串的结尾?

Can you help me what is the usage of $ in the following regular expression; I don't understand what is the usage? Does it mean just the end of string?

p.match(/^\.\.?($|\/)/)

推荐答案

让我们解构您的正则表达式(为简化起见,我删除了用于转义字符的反斜杠,在这里我们将点和斜杠用作文字)我们剩下的是:

Let's deconstruct your regex (I removed the backslashes that are used to escape characters for the sake of simplification, we will use the dots and slashes as literal here) so we're left with :

^ ..?($ |/)

  • ^ 表示一行的开头
  • .然后我们必须有一个点
  • .?,那么我们可能没有第二个点
  • $ |/最后,我们要么结束行(这就是 $ 符号的作用),要么在/ <之后继续/li>
  • ^ means the beginning of a line
  • . then we must have a dot
  • .? then we may or may not have a second dot
  • $|/ and finally, we either end the line (that's what the $ sign does), or continue after a /

括号用于返回变量中的内容.

The parenthesis are used to return what's inside it in variables.

您的正则表达式将检测以下字符串:

Your regex will detect the following strings :

..
../
./
../anytext
./anytext

希望这会有所帮助.

这篇关于正则表达式中美元符号的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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