I guess this is silly question, but I am confused as to how can regex .* match all the strings?
*: zero or more occurrences of the preceding element,
.: matches any one character,
So, in .*, . should match any one character( say 'x'), then * would mean 0 or more occurrences of 'x',
thus giving us strings like:
"",
"x",
"xx",
"xxx",
"xxxxxxx",.. etc.
But how is it able to match any random string like "ab12b3v34"?
Shouldn't this be actually the case for [.*]*?
What am i missing here please explain.
My confusion was due to my ignorance of order of evaluation.
I thought the evaluation went as follows(which is wrong):
.*,.is evaluated first, say.is replaced by 'x'. Here 'x' is just a literal character.x*would be evaluated leading to strings like "", "x", "xx", "xxx", ...etc.But the correct order of evaluation is:
.*,*is evaluated first, thus resulting in another regex pattern like,.,..,..., ...etc, where.are still wildcards..is/are replaced by any character, thus resulting in string(without new-line character) such as "ab12b3v34"(in this case from.........).Thanks to all who commented for your patience.