M. Kasinski
M. Kasinski

Reputation: 21

RegEx for matching URLs with trailing slash

I am trying to write an expression for AngularJs. I need to use it inside an ng-pattern directive so to put a validation constraint to a form.

What I actually need is a regex for a URL in https that has always to end with a slash: /.

It would be nice if it ends more specifically in /pre/last/

How do I solve this problem?

Upvotes: 1

Views: 1557

Answers (2)

Emma
Emma

Reputation: 27743

This RegEx might help us to match /pre/last/. It creates two groups, in case we wish to call those groups, we can do so using $2 for /pre/last/ and $1 for first the part of our URL (Please see the image).

 '/(.+)(\/pre\/last\/)/g'

We might not want to bound it with start (^) or end ($) anchors, and it might still does our desired matchings.

enter image description here

This post explains how we would do so in JavaScript.

Upvotes: 4

Za101
Za101

Reputation: 521

Maybe this help

/.*\/pre\/last\/$/g

what it basically match is any string that ends with /pre/last/

Upvotes: 0

Related Questions