Gergely Lukacsy
Gergely Lukacsy

Reputation: 3074

Codeception URL regex

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+)~');

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?

Upvotes: 1

Views: 564

Answers (1)

Naktibalda
Naktibalda

Reputation: 14102

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.

Upvotes: 3

Related Questions