use regex in php code example

Example 1: preg_match

if(!preg_match('/^\[a-zA-Z]+$/',$input)) {
   // String contains not allowed characters ...
}

Example 2: php regex

preg_match('/(foo)(bar)(baz)/', 'foobarbaz', $matches, PREG_OFFSET_CAPTURE);

Example 3: php regular expression

Modifier	Description
i 	Makes the match case insensitive
m 	Specifies that if the string has newline or carriage
	return characters, the ^ and $ operators will now
	match against a newline boundary, instead of a
	string boundary
o 	Evaluates the expression only once
s 	Allows use of . to match a newline character
x 	Allows you to use white space in the expression for clarity
g 	Globally finds all matches
cg 	Allows a search to continue even after a global match fails

Example 4: What is a Regular Expression in php

A regular expression is a sequence of characters that forms a search pattern.

Tags:

Misc Example