tags:

views:

159

answers:

2

Sure it's a regular expression's newbie question, I saw it in a program but I can't understand the part of the two backslashes, Does "\\" have a special meaning like \r or \t?

[a-zA-Z]+\\.?

Thank you

+8  A: 

The backslash (\) is the escape character in your regular expression pattern which is why \r and \t work, they are regular characters preceded with the escape character to denote a special character you can't just type on your keyboard. To tell the pattern matcher that it should look for an actual backslash, which is what your pattern is doing, you have to escape it thus creating \\.

Cryo
Cryo is right, \ is the escape character, you will see it in most modern high level programming languages.
Jay Zeng
+5  A: 

Yes, \ is the escape character in Regex. \\ means \ and \. means a single dot while a single dot means any character. If you see that inside a string in a language like C, the double slashes will be picked up by the language compiler and the string will be really \. which will be parsed by the regex engine as a single dot.

Mehrdad Afshari
Nice catch on the potential 'double escape'.
ProfK