0

I have this regular expression \\..\\{3\\}$

I want to understand how this expression works to match a string. My thought is that it matches any 8 characters at the end of the line. Is that how this expression works?

If so, I think something like this would match the string:

rs.efg$tu

1 Answer 1

2

Assuming "typical" regexp's (sadly, different tools handle slightly different rexexps, and the GNU and POSIX versions are also different, and then there has been some version drift...), this parses as [Need Unicode-Art in markup...]

\.  . \{3\} $
 ▲  ▲   ▲   ▲
 │  │   │   │
 │  │   │   └─ End of line
 │  │   └─ Preceding exactly 3 times (the '\' makes '{' special...)
 │  └─ Any character (except '\n')
 └─ A literal '.' ('.' is special, '\' makes it un-special)

So this means a dot and 3 random characters before the end of the line.

Constructions like * or \{3\} (if the last one is even supported) apply to the last character, or the last parentesis (probably \( ... \), but that is again regexp-dialect-dependent). Check the manual for the exact tool you are using.

4
  • 1
    This not quite right. His first . is escaped, so it is a literal .. Good ASCII breakdown though.
    – jordanm
    Commented Mar 7, 2013 at 20:00
  • 1
    I see I forgot that the first . was escape so I counted that in during the process of matching character, thank you very much Commented Mar 7, 2013 at 20:05
  • Strange... I swear I didn't see that. Fixing. Thanks!
    – vonbrand
    Commented Mar 7, 2013 at 20:07
  • You seem to have forgotten the initial backslash.
    – Kusalananda
    Commented Sep 21, 2017 at 8:42

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .