Reputation: 307
I have a text box, for the user to paste an embed tag inside it, but i want to validate, weather a user is not entering any other code other than an embed tag, hence i need to validate an embed tag.
Upvotes: 0
Views: 85
Reputation: 7273
\s*(https?://)www.youtube(-nocookie)?.com/(?:v|embed)/[\p{L}\p{N}]+[\p{L}\p{N}\p{Zs}.#@$%+&;:_~,?=!/-]*\s*
I took the liberty to remove unnecessary capture groups, escapes and characters.
Although I personally would use something like:
\s*(https?://www.youtube(?:-nocookie)?.com/(?:v|embed)/([a-zA-Z0-9-]+).*)
That puts the entire youtube URL in match group 0 and the video id in match group 1. Also it doesn't make a whole lot of sense to use unicode properties when youtube's URLs don't contain unicode characters.
Demo: http://rubular.com/r/jv4zO9ys2L
Upvotes: 1