I have this string:
videos/000/000/021/10f43ddb374开发者_C百科72ee4bb57_original.m4v
I need this part:
videos/000/000/021/
So format is:
videos/{3 digit number (000-999)}/{3 digit number (000-999)}/{3 digit number (000-999)}/
videos/(\d{3}/){3}
Meaning: "videos/"
followed by three digits and a forward slash three times
^videos/(\d{3})/(\d{3})/(\d{3})/
Explanation:
\d
matches a digit.{3}
requires three of the previous item.^
anchors the match at the beginning of the string so "videos/111/222/333/" matches but "othervideos/111/222/333/" does not.- Parentheses can be used to capture the three numbers so you can examine them in a later step; in some languages they'll be available as
$1
,$2
, and$3
.
videos/([0-9]{3}/){3}
If your regex flavor needs forward slash delimiters,
/videos\/([0-9]{3}\/){3}/
精彩评论