1

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?

Emma
  • 27,428
  • 11
  • 44
  • 69
  • can you show what have tried ? – Yassine CHABLI Apr 20 '19 at 13:38
  • 1
    @Emma It is not working. I don't need a rewrite expresion but something to use in angularjs ng-pattern – M. Kasinski Apr 20 '19 at 17:30
  • 1
    I would like something like this to be accepted: https ://SOMETHING_HERE/pre/last/ and not be accepted if the last slash is missing like https ://SOMETHING_HERE/pre/last. But it has to have the /pre/last always. – M. Kasinski Apr 21 '19 at 08:51

2 Answers2

4

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.

Emma
  • 27,428
  • 11
  • 44
  • 69
0

Maybe this help

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

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

Za101
  • 451
  • 3
  • 6