Home > Net >  Regex for finding URL match if nothing and after the URL but ignore if found in multiline
Regex for finding URL match if nothing and after the URL but ignore if found in multiline

Time:04-18

Guys I need to create a regex of a URL https://www.test.com/88f19 (last 5 digits can change) and I came up with https:\/\/www.test.com\/[a-fA-F0-9]{5} and it works fine. But the problem is that I only need to match this URL if and only if nothing exists before and after this URL. e.g. this should match https://regex101.com/r/LdfVFW/1 whereas this should not match since there is some other text in multi line with the URL https://regex101.com/r/namAOd/1. Would appreciate some inputs!

CodePudding user response:

Use \A (start of all input) and \Z (end of all input) at either end:

\Ahttps:\/\/www.test.com\/[a-fA-F0-9]{5}\Z

See live demos:

  • Related