-1

I need regular expression of url such as below

http://www.aparat.com/v/bqn5H
http://www.aparat.com/v/raozG
http://www.aparat.com/v/wKZOY
http://www.aparat.com/v/noopj

I wrote one but I think it doesn't work

http:\/\/www\.aparat\.com\/v\/([a-zA-Z0-9-_]+)
DrC
  • 7,528
  • 1
  • 22
  • 37
Amir
  • 33
  • 7

4 Answers4

2

Your regex is correct. I think you are forgetting the g modifier.

See here: http://regex101.com/r/tJ1wR5

Also see: What is the best regular expression to check if a string is a valid URL?

Community
  • 1
  • 1
Chankey Pathak
  • 21,187
  • 12
  • 85
  • 133
0

Works fine with using the word (\w) with one or more quantifier

http:\/\/www\.aparat\.com\/v\/\w+
Saif Asif
  • 5,516
  • 3
  • 31
  • 48
0

I checked my code and I found that this is not exactly what I need. this is the best fit regular expression:

http:\/\/www\.aparat\.com\/v\/.*([a-z0-9-_]+)
Amir
  • 33
  • 7
0

The following code supports

  1. http and https
  2. www and without www

code:

^((?:https?:)?\/\/)?((?:www|m)\.)?((?:aparat(-nocookie)?\.com))(\/(?:[\w\-]+\?v=|embed\/|v\/)?)([\w\-]+)(\S+)?$

https://regex101.com/r/y5atof/1