Codeception URL regex

痞子三分冷 提交于 2019-12-13 02:18:12

问题


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+)~');
  • Without the tilde sign, it gives an error. eg. grabFromCurrentUrl('(\d+)') returns:

    " (\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

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?


回答1:


Codeception doesn't use any special regex functions.

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

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.



来源:https://stackoverflow.com/questions/51742632/codeception-url-regex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!