Restriction of characters at the end of regex

2

I need to have a regex capture urls that only end with letters or numbers.

I have this regex here:

(https?)(:\/\/www.site.com.br)(\S){1,}

As it is, this regex allows urls to end with characters like @,!,?, etc.

I tried doing this using lookbehind but I could not. How can I make this character constraint only at the end of the regex?

    
asked by anonymous 11.08.2017 / 17:01

1 answer

2

Try this:

^https.+[\w]$

The idea is to set anchors at the beginning and end of the file:

  • ^https : Requires the URL to start with https ;
  • [\w]$ : Requires the URL to end with any numeric alpha character, is the equivalent of [a-zA-Z0-9_] ;
  • dot ( . ): Indicates any characters;
  • plus ( + ): one or more characters
11.08.2017 / 17:54