Skip to main content

Posts

Showing posts with the label preg_match

How Regular Expression works in PHP?

Regular Expression, commonly known as RegEx is considered to be one of the most complex concepts. However, this is not really true. Unless you have worked with regular expressions before, when you look at a regular expression containing a sequence of special characters like /, $, ^, \, ?, *, etc., in combination with alphanumeric characters, you might think it a mess. RegEx is a kind of language and if you have learnt its symbols and understood their meaning, you would find it as the most useful tool in hand to solve many complex problems related to text searches and validations. Basic Syntax of Regular Expressions First of all, let's take a look at two special symbols: '^' and '$' . What they do is indicate the start and the end of a string, respectively, like this: " ^The ": matches any string that starts with "The"; " of despair$ ": matches a string that ends in the substring "of despair...