What Is a Regular Expression in PHP ?

Regular expression provides a special syntax for searching for patterns of text within strings. A regular expression is simply a string of search text. Regular expressions are included by delimiters (usually slashes).

For example, this simple regular expression searches for the word “ csitquestion ” anywhere within the target string:

/csitquestion/

Regular expressions start to become useful once insert additional characters that have special meanings.

For example, the caret (^) character at the start of the expression means “ the following characters must appear at the start of the target string ” :

/^csitquestion/

This example will match the string “csitquestion ”, but not the string “ hello,csitquestion”.

Scroll to Top