Home

Photography

Ethics

Politics

Ideas

Technology

Academic

Blog

Pete Bagnall

PHP Regex builder

Enter your pattern into the field below. New-lines are removed before the pattern is tested, so you can lay out your pattern to make it easier (ie possible!) to read. The pattern ends after a blank line, so if you have spare bits of pattern you're testing you can just leave them lying around below the pattern without any problems.

Pattern:

Test String:

Match 0

\0 = <img src='hello.jpg'>
\1 =
\2 =

Match 1

\0 = <img src="hello.jpg">
\1 =
\2 =

Match 2

\0 = <img src=hello.jpg>
\1 =
\2 =

PHP Pattern String (escaped with \\ and \")

/<img(?:\\s*)(?:.*)(?:\\s*)src(?:\\s*)=(?:\\s*)(['\"]?)([^'\"]*)\\1(?:\\s*)(?:.*)(?:\\s*)[\\/]?>/sU

or as a php string for readability in your code
="/<img(?:\\s*)(?:.*)(?:\\s*)src(?:\\s*)=(?:\\s*)(['\"]?)([^'\"]*)\\1(?:\\s*)(?:.*)(?:\\s*)[\\/]?>/sU"


© Peter Bagnall