I have this regex:
preg_match("/(comment|vid|nice)/i", $id)
And I want vid
part to match with video
or ivideo
.
What's the right way to add asterisks in vid
so it matches with those terms?
I have this regex:
preg_match("/(comment|vid|nice)/i", $id)
And I want vid
part to match with video
or ivideo
.
What's the right way to add asterisks in vid
so it matches with those terms?
Surely there are many options for this, but one that comes to mind is
preg_match("/(comment|[\w-]*vid[\w-]*|nice)/i", $id)
whereas
\w
matches A-Z
, a-z
, 0-9
and _
-
simply matches -
[...]
is a character class, so it matches both 1. and 2.*
means matching 0 or more timesBtw you can fiddle with the matches by simply using an online tester like http://www.regextester.com.