Tilde operator in Regular expressions

In this case, it’s just being used as a delimiter.

Generally, in PHP, the first and last characters of a regular expression are “delimiters” to mark the start and ending position of a matching portion (in case you want to add modifiers at the end, like ungreedy, etc)

Generally PHP works this out from the first character in a string that is meant as a regular expression, matching the second occurence of it as the second delimiter. This is useful where you have an occurrence of the normal delimiter in the text (for example, occurences of / in the text) – this means you don’t have to do awkward things.

Matching for “//” with the delimiter set to “/

/\/\//

Matching for “//” with the delimiter of “#

#//#

Leave a Comment