HardCoreMore Posted December 7, 2010 Share Posted December 7, 2010 Hi guys, I started to learn regex and was doing just fine until i saw (?:[A-Z0-9-]+\.) I just can't find anywhere what ?: does in regex. More correctly this two patterns 1. This one is for email [A-Z0-9._%+-]+@(?:[A-Z0-9-]+\.)+[A-Z]{2,4} In this one the part with ?: should prevent users entering email like john@aol...com. 2. Second one is /^(?:br|frame|hr|img|input|link|meta|range|spacer|wbr|area|param|col)$/i I know that ? is used to match 0 or 1 times but don't know what does ?: is for and is that only to be used inside () Thanks Quote Link to comment https://forums.phpfreaks.com/topic/220941-in-regex/ Share on other sites More sharing options...
requinix Posted December 7, 2010 Share Posted December 7, 2010 (? means that the capturing group has special behavior, depending on what comes after the question mark. A colon means that the parentheses don't actually capture text (which is what they normally do). That is, there is no \1 or $1 assigned to it. Quote Link to comment https://forums.phpfreaks.com/topic/220941-in-regex/#findComment-1144096 Share on other sites More sharing options...
salathe Posted December 7, 2010 Share Posted December 7, 2010 To elaborate a little more on what requinix said, this page has a little more detail (though it can get quite eye-glazingly technical) — http://php.net/regexp.reference.subpatterns Quote Link to comment https://forums.phpfreaks.com/topic/220941-in-regex/#findComment-1144113 Share on other sites More sharing options...
HardCoreMore Posted December 23, 2010 Author Share Posted December 23, 2010 Hi Guys, @requinix, @salathe Thanks for your reply. @salathe I am reading it second time already. I understand it for the most part but not quite complete yet. Probably will read it one more time to understand it completely. But there is something they said there that i don't know the reason for. Qute "The maximum number of captured substrings is 99, and the maximum number of all subpatterns, both capturing and non-capturing, is 200. " Does anyone knows why is there a limit to number of captured substrings and subpattenrs? What i have a really big text file or multiple text files combined that i want to test regex on? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/220941-in-regex/#findComment-1150674 Share on other sites More sharing options...
.josh Posted December 24, 2010 Share Posted December 24, 2010 I have never in my life ever seen someone need to use more than 99 groups, or even 50...or even 10. Most patterns use 0-5 groups. Beyond that, it is usually far more beneficial to be breaking down the data (with or without regex) into smaller chunks of data to work with...or going back and rethinking how you are storing that data in the first place.. I have once or twice seen a regex that used upwards of 10 and one time I think I used almost 20 groups for a particularly complex pattern for someone (it was parsing some custom serialized multi-dim array, matching only certain areas of the subject if other areas matched, etc.. ) but TBH it was more out of me trying to be cool and get all the data out in one regex than doing things the "better" way in the first place (particularly pushing back and saying 'store your shit better'). IOW, if you really think you need anywhere near that many captured groups, the chances are overwhelmingly likely that you are going about storing the data and/or approaching the regex in the wrong way. I have yet to see any evidence from real world examples/problems where you would actually ever need anywhere near that many groups. Quote Link to comment https://forums.phpfreaks.com/topic/220941-in-regex/#findComment-1151136 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.