What is the difference between `?` and `.`?

0104

The difference between ? and . in regular expressions is as follows:

  • . (Dot): Matches any single character except for newline characters. For example, the pattern a.b will match aab, acb, a1b, etc., where any character can be in place of the dot.

  • ? (Question Mark): Acts as a quantifier that indicates that the preceding element is optional, meaning it can appear 0 or 1 time. For example, the pattern ab?c will match ac (where b is absent) and abc (where b is present).

Summary:

  • . = Matches any single character.
  • ? = Indicates that the preceding character or group is optional (0 or 1 occurrence).

If you need further clarification or examples, feel free to ask!

0 Comments

no data
Be the first to share your comment!