eXeCuTeR Posted November 13, 2007 Share Posted November 13, 2007 What does the .* mean? I know it's 2 tags and not 1 but sometimes people write it and it seems so stupid for me. Why? . means all characters except \n * means 1 or more characters. and sometime they end it like this: .*? Would you please explain me this? Thanks. Quote Link to comment Share on other sites More sharing options...
effigy Posted November 13, 2007 Share Posted November 13, 2007 . is a metacharacter which matches all characters except a new line. It encompasses all characters if the /s modifier is used. * is a quantifier which will try to match as many characters as possible, but is allowed to match nothing at all. Adding a ? to a quantifier makes it lazy. By default, all quantifiers try to match their maximum first. When made lazy, they try to match their minimum first. Quote Link to comment Share on other sites More sharing options...
eXeCuTeR Posted November 13, 2007 Author Share Posted November 13, 2007 You didn't answer my question. Why do they use . and then * together? Thanks for the explanation tho. Quote Link to comment Share on other sites More sharing options...
effigy Posted November 13, 2007 Share Posted November 13, 2007 Quantifiers quantify things. If you only use . it means match one instance. When you add * you modify the quantity of ., which then looks for 0 to any number of instances of ., instead of only one. See this page for more information. Quote Link to comment Share on other sites More sharing options...
eXeCuTeR Posted November 14, 2007 Author Share Posted November 14, 2007 Oh, the . quantifier matches only 1 character? Quote Link to comment Share on other sites More sharing options...
Azu Posted November 14, 2007 Share Posted November 14, 2007 . matches one character .* matches 0 to infinity characters .+ matches 1 to infinity characters . is like .{1,1} .* is like .{0,9999999999999999999999} .+ is like .{1,9999999999999999999999} Quote Link to comment Share on other sites More sharing options...
effigy Posted November 14, 2007 Share Posted November 14, 2007 Oh, the . quantifier matches only 1 character? . is not a quantifier--it's a metacharacter. Anything without a quantifier is expected to match once. It makes sense if you think about it. If you type "a" in your pattern, you expect it to match just "a"--not "aa", "aaa", "aaaaa", etc. Therefore, this same logic applies to metacharacters. Quote Link to comment Share on other sites More sharing options...
eXeCuTeR Posted November 14, 2007 Author Share Posted November 14, 2007 Thanks guys, you helped me Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted November 15, 2007 Share Posted November 15, 2007 .* is like .{0,9999999999999999999999} .+ is like .{1,9999999999999999999999} Err... no it isn't. * corresponds to {0,} and + corresponds to {1,} Quote Link to comment Share on other sites More sharing options...
Azu Posted November 16, 2007 Share Posted November 16, 2007 No need to be a smartass. We know it doesn't literally mean that number I posted. I was just trying to explain in a way that would be easily understandable since he doesn't know much about regex. Quote Link to comment Share on other sites More sharing options...
effigy Posted November 16, 2007 Share Posted November 16, 2007 No need to be a smartass. We know it doesn't literally mean that number I posted. I was just trying to explain in a way that would be easily understandable since he doesn't know much about regex. What Daniel posted is the correct syntax for those quantifiers. Just because "we" know, doesn't mean the people reading this post do. There's no need to call someone a smart ass for correcting you. Quote Link to comment Share on other sites More sharing options...
Azu Posted November 16, 2007 Share Posted November 16, 2007 Okay I think there's a misunderstanding. I was trying to explain how the quantifiers work to the person that did not understand how they work. So saying {1,} probably would have made no sense to him. It's usually safe to assume that a long line of 99999s means infinity in such a case. Quote Link to comment Share on other sites More sharing options...
Daniel0 Posted November 16, 2007 Share Posted November 16, 2007 Since when will posting incorrect information help the person who doesn't understand it? Quote Link to comment Share on other sites More sharing options...
Azu Posted November 16, 2007 Share Posted November 16, 2007 Nevermind... I'm not going to argue with someone who tries to misinterprate me on purpose. :/ Quote Link to comment 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.