in reply to Please correct me in the above regular expression

hippo has shown++ the regex you must use to match any or all of the substrings .abc (abc abc in the string "int abc;\n.abc(abc)".

A narrative explanation may be useful. The regex pattern [\.(] (or [.(] which I will use from here on; the escape is not needed in a character class, but does no harm) defines the characters in a class. The regex [.(]abc requires that a character from the class and the following 'abc' characters all be present for a match to occur.

++++------- a single character from this class (an "atom") |||| is required vvvv [.(]abc ^^^ ||| +++---- all these characters are required
So 'int abc;' cannot match because 'abc' is not preceded by a required "atom": a character from the character class.

On the other hand, the regex pattern [.(]?abc can match something in 'int abc;' because the character class has been made optional by the ? (0 or 1) quantifier:

++++------- a character from this class is an "atom" |||| |||| +++--- all these characters are required |||| ||| vvvv vvv [.(]?abc ^ | +------ 0 or 1 of preceding "atom" is required

In the context of this discussion, an "atom" can be thought of as anything that can be quantified by the * ? + {} quantifiers; see discussions of quantifiers in Regular Expressions in perlre and Matching repetitions in perlretut.


Give a man a fish:  <%-{-{-{-<