1
^[a-zA-Z]:{1}/(\w+/)+$

I want to allow . as well in the expression in \w+. How can I do this?

strager
  • 86,676
  • 24
  • 133
  • 174
maztt
  • 12,167
  • 19
  • 75
  • 149
  • 1
    `{1}` is completely redundant, by the way, `:{1}` makes **:** match only once, which is the same as `:`. – Kobi Jul 08 '10 at 09:06
  • To add to Kobi's excellent point: http://stackoverflow.com/questions/3032593/using-explicitly-numbered-repetition-instead-of-question-mark-star-and-plus – polygenelubricants Jul 09 '10 at 10:58

4 Answers4

9

\. should do it. You don't need the escaping \ if you put it in a character class. For your exact example:

^[a-zA-Z]:{1}/([\w.]+/)+$
Carl Norum
  • 210,715
  • 34
  • 410
  • 462
3

The . is a special character in regular expression syntax, so you have to escape it with a backslash. \.

Bill the Lizard
  • 386,424
  • 207
  • 554
  • 861
1

Replace

(\w+/)

with

([\w.]+/)
strager
  • 86,676
  • 24
  • 133
  • 174
0

The expression should be ^[a-zA-Z]:/(\w+./)+$ or ^[a-zA-Z]:/([\w.]+/)+$

serhio
  • 27,402
  • 58
  • 213
  • 366