poirot Posted June 13, 2006 Share Posted June 13, 2006 I think I finally grasped Regex... Everything seems to be easier =)There is still something that bugs me... What are pattern delimiters for?I know you need them, but why? Is there a specific reason for the need of delimiters?When you use for example preg_match("pattern", ...) why can't PHP understand "pattern" is a regex pattern and "forget" the delimiter?Thanks in advance Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/ Share on other sites More sharing options...
Koobi Posted June 13, 2006 Share Posted June 13, 2006 i think it's because PHP is just the glue language. it needs to pass on this regex to the regex engine which is independant of PHP's engine.And PHP won't add the delimiters on it's own because what if your pattern consisted of an instance of that delimiter? You would have to escape it so that it is taken literally...and that can be annoying if you have many instances of that delimiter, therefore, PHP gives us the option to specify the delimiters as well.case in point:this is fine[code]<?php //example: match either 4 or more lower case alphabets preg_match('/[a-z]{4,}/', ...);?>[/code]this looks messy[code]<?php //example: match a simple url preg_match('/^http:\/\/[a-z]+\.com\//', ...);?>[/code]i used my own delimiters instead of the common one (/)[code]<?php //example: match a simple url preg_match('%^http://[a-z]+\.com/%', ...);?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-45182 Share on other sites More sharing options...
effigy Posted June 13, 2006 Share Posted June 13, 2006 In addition to Bane's comment, regular expressions also have modifiers. You can't leave the modifier dangling outside of the string ("pattern"i), nor could you assume the last character within the string was a modifier ("patterni"). Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-45191 Share on other sites More sharing options...
poirot Posted June 14, 2006 Author Share Posted June 14, 2006 I guess effigy's comment makes more sense, since you only need to escape delimiters/use different delimiters because of their existence itself. PHP being a glue language is not an answer, because this would only change the question to the regex engine: "why does the regex need delimiters"?Thankseffigy, are you Jeffrey Friedl? Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-45306 Share on other sites More sharing options...
effigy Posted June 14, 2006 Share Posted June 14, 2006 Delimiters are important through all programming; they serve as containers which improve and/or allow more complex syntax.No, I am far from Friedl, but I do enjoy his book. Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-45559 Share on other sites More sharing options...
bilis_money Posted June 14, 2006 Share Posted June 14, 2006 i'm not very good on PHP but it has a good relativity with C.which i had an experience before.delimeter is the mark that makes the string to look as string.i think my grammar is right. and recognize by the php language as a string.i hope these are correct. he, he, he Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-45600 Share on other sites More sharing options...
bilis_money Posted June 14, 2006 Share Posted June 14, 2006 [quote]effigy, are you Jeffrey Friedl?[/quote]if i'm not mistaken you are talking about the author of "Mastering Regular Expression". Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-45609 Share on other sites More sharing options...
DjiXas Posted October 2, 2007 Share Posted October 2, 2007 Can anyone tell me what symbols needs to be seperated with \ and how exactly to seperate, just put \ before any symbol?Like if url is[code]preg_match_all('http://www.domain.com/index.php?article=(.*)')[/code]Make it like this:[code]preg_match_all('http\:\/\/\www\.domain\.com\/index\.php\?article\=(.*)')[/code] ??? Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-360089 Share on other sites More sharing options...
effigy Posted October 2, 2007 Share Posted October 2, 2007 You still don't have delimiters--they go around your pattern. All metacharacters that should be matched as a literal need to be escaped. In your example that includes[tt] / [/tt] (if used as a delimiter),[tt] .[/tt], and [tt] ?[/tt]. Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-360099 Share on other sites More sharing options...
DjiXas Posted October 2, 2007 Share Posted October 2, 2007 How it should look with delimiters then? ??? Sorry, just started learning php. Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-360368 Share on other sites More sharing options...
effigy Posted October 2, 2007 Share Posted October 2, 2007 I thought this topic explained it.... See if [url=http://weblogtoolscollection.com/regex/regex.php]this[/url] link helps. Look for "Perl Style Delimiters." Quote Link to comment https://forums.phpfreaks.com/topic/11905-regex-question/#findComment-360382 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.