开发者

What would the regex be for this?

开发者 https://www.devze.com 2023-01-25 20:42 出处:网络
I have this string: videos/000/000/021/10f43ddb374开发者_C百科72ee4bb57_original.m4v I need this part:

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}/
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号