in reply to Re^2: regex not matching how I want it to :(
in thread regex not matching how I want it to :(
I would suggest however that you probably want to avoid quantifiers such as * or + with the match-all dot (i.e. the .* and .+ patterns) when possible, and even also .*? and .+?, although these latter two are much less dangerous in terms of matching more than what you want.
It is often safer and better to be more specific on the characters you want to match, using the appropriate character class. In the case in point, using a regex like /<a href=\"(\w*?)\.htm\">/ig would probably be safer, because, with \w+ or \w*, you're guaranteed to match only alphanumeric characters (and possible underscores), so you know for sure that you're not gonna match any tag-opening and tag-closing characters (angle brackets), backslashes, quote marks, etc.
As for your latest code you posted, [^<br>]*? doesn't do what you probably think it does, even though you report that the result happens to be what you want. [^<br>] is a negative character class that matches everything except the following individual characters: < > b r. I doubt somewhat that what you really meant it to be. The fact that it contains the < character (and will therefore stop matching at the first tag-opening character) is probably enough to save your day in this specific case, but be aware that it won't work if the string that you want to retrieve contains any "b" or any "r."
HTH.
|
|---|