Codeception URL正则表达式 [英] Codeception URL regex

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

问题描述

因此,官方文档对正则表达式模式中使用的代字号()绝对没有任何说明,例如 seeCurrentUrlMatches()函数。但是,它在文档中得到了广泛使用。

So the official documentation says absolutely nothing about the tilde sign (~) used in regexp patterns, for example as in the seeCurrentUrlMatches() function. Yet, it is used extensively in the documentation.

在示例中,正则表达式看起来像这样:

In the exmample, the regexp looks like this:

    $I->seeCurrentUrlMatches('~$/users/(\d+)~');




  • 如果没有波浪号,则会出现错误。例如。 grabFromCurrentUrl('(\d +)')返回:

    • Without the tilde sign, it gives an error. eg. grabFromCurrentUrl('(\d+)') returns:


      (\d +)没有失败。

      " (\d+)" Fail Nothing to grab. A regex parameter required.


    • 字符串结尾的正则表达式运算符( $
      的位置没有任何意义(我认为美元符号在这种情况下完全具有
      的不同含义, /我的猜测将是本国路径的简写/。)

    • 在标准正则表达式中,捕获字符本身

    • The end-of-string regexp operator's ($) position makes no sense (I presume the dollar sign has a completely different meaning in this context /my guess would be shorthand for the home path/.)
    • In standard regexp, the ~ captures the character itself
    • 我的结论是Codeception期望您使用的正则表达式模式显然是非标准的。那么 $ 的作用是什么?在哪里可以找到有关此内容的完整文档或文章?

      My conclusion is the regexp pattern that Codeception expects from you is clearly non-standard. So what does the ~ and $ do? Where can I find a throughout documentation or article about this?

      推荐答案

      Codeception不使用任何特殊的正则表达式函数。

      Codeception doesn't use any special regex functions.

      seeCurrentUrlMatches 方法调用PhpUnit的 assertRegexp 方法,该方法使用 preg_match

      seeCurrentUrlMatches method calls PhpUnit's assertRegexp method which uses preg_match under the hood.

      preg_match 使用模式定界符。分隔符可以是任何非字母数字字符。
      / 是最常见的定界符,但是它不方便匹配URL,因为您必须在URL中转义很多斜线,因此使用作为分隔符避免了转义。

      preg_match uses pattern delimiters. Delimiter can be any non-alphanumeric character. / is the most common delimiter, but it is inconvenient for matching URL, because you would have to escape a lot of slashes in URL, so using ~ as a delimiter avoids need to escape.

      $ 在示例中,模式开头可能是一个简单的错误。

      $ at the beginning of pattern is probably a simple mistake in example.

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

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