Regular Expressions 101

Community Patterns

Get all HREF attributes, including parameters, if document ends in .cfm(l) or .htm(l)

0

Regular Expression
PCRE (PHP <7.3)

/
href=['"]([^'"]*)\.(cf|ht)ml?(\?{1}([^'"]*))?['"]
/
g

Description

If you have the source code for any page and want to get all HREF attributes and values, including URL params, that end in .cfm, .cfml, .htm, or .html. Can be easily modified for whatever document type you want (.asp, .aspx, .jsp, etc.)

I needed to do this for a project. It took me a long time to fiddle it into working shape, so I thought I'd share it for anyone else that might need it.

Submitted by anonymous - 7 years ago