Pradeep Kumar
Pradeep Kumar

Reputation: 5

Need regular expression for the URL

I have a following regular expression in VB

(http[s]?|rtsp|qvmc|rtmp)://(([^/:\.[:space:]]+(\.[^/:\.[:space:]]+)*)|([0-9](\.[0-9]{3})))(:[0-9]+)?((/[^?#[:space:]]+)(\?[^#[:space:]]+)?(\#.+)?)?

and URL I have :

rtsp://root:[email protected]/axis-media/media.amp?videocodec=h264&audio=1>rtsp_transport=udp_multicast>recordingfilename=c:\folder\recfile.mp4

Unable to pass match with the above regular expression, Can anyone suggest what is the mistake in Regular expression.

Upvotes: 0

Views: 781

Answers (1)

LukStorms
LukStorms

Reputation: 29667

Your regex doesn't have something to match the username and password before the @.
While your URL has a user and password, so it won't match.

And don't use a POSIX character class like [:space:] in .NET

This pattern will also capture the username and password:

(https?|rtsp|qvmc|rtmp):\/\/(?:([^\s@\/]+?)[@])?([^\s\/:]+)(?:[:]([0-9]+))?(?:(\/[^\s?#]+)([?][^\s#]+)?)?([#]\S*)?

Upvotes: 1

Related Questions