tmyonline Posted March 4, 2008 Share Posted March 4, 2008 Hi guys, I'm trying to understand the syntax of the preg_match(). Below is the sample code from php.net <?php $subject = "abcdef"; $pattern = '/^def/'; preg_match($pattern, substr($subject,3), $matches, PREG_OFFSET_CAPTURE); print_r($matches); ?> The $pattern contains a string '/^def/' . Two questions: why do I need the ' / ' character at the beginning and ending of this string ? Also, what does the ' ^ ' character mean and why is it there ? Thanks. Link to comment https://forums.phpfreaks.com/topic/94324-trying-to-understand-the-preg_match-syntax/ Share on other sites More sharing options...
sasa Posted March 4, 2008 Share Posted March 4, 2008 / - start and end of pattern, you can use some comand out of that ^ - start of string Link to comment https://forums.phpfreaks.com/topic/94324-trying-to-understand-the-preg_match-syntax/#findComment-483080 Share on other sites More sharing options...
The Little Guy Posted March 4, 2008 Share Posted March 4, 2008 you don't have to use / you can use ~ as well... basically some non-string character.. but not all of them, because the have certain meanings. Link to comment https://forums.phpfreaks.com/topic/94324-trying-to-understand-the-preg_match-syntax/#findComment-483091 Share on other sites More sharing options...
discomatt Posted March 4, 2008 Share Posted March 4, 2008 Here's a little help with regex: http://www.regular-expressions.info/ Bit of an advertisement for their product, but a very good tutorial and reference as well. Link to comment https://forums.phpfreaks.com/topic/94324-trying-to-understand-the-preg_match-syntax/#findComment-483098 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.