Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

meaning of the letter "~" in regex [duplicate]

Tags:

regex

php

what is the meaning of the "~" in regex .For example in this code

preg_match("~^(\(\d+\)|\d+\-)?\d{10,20}$~",$value)

this code check for wether the phone number contains extension or not. I have tried to remove to the "~" in this code and got an error like this:

Warning: preg_match() [function.preg-match]: No ending delimiter '^' found in C:\xampp\htdocs\test\my_application\Phone.php on line 21

like image 314
An Nguyễn Lê Thái Avatar asked Sep 22 '13 15:09

An Nguyễn Lê Thái


Video Answer


1 Answers

This character is called Tilde and in this case is simply a placeholder, it's just being used as a delimiter. It is simply delimiting the start and end of your regex pattern.

like image 94
aleroot Avatar answered Sep 29 '22 12:09

aleroot