Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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:


share|improve this question
up vote 2 down vote accepted

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.

share|improve this answer
This not quite right. His first . is escaped, so it is a literal .. Good ASCII breakdown though. – jordanm Mar 7 '13 at 20:00
I see I forgot that the first . was escape so I counted that in during the process of matching character, thank you very much – user1763658 Mar 7 '13 at 20:05
Strange... I swear I didn't see that. Fixing. Thanks! – vonbrand Mar 7 '13 at 20:07

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.