Regular expressions matching strings in relative path, not in domain

This is one of my interviews. I did not come up with a good enough solution and was refused.

The question was

What is the one regex to match all urls that contain job(case insensitive) in the relative   
path(not domain) in the following list:

    - http://www.glassdoor.com/job/ABC
    - https://glassdoor.com/job/
    - HTTPs://job.com/test
    - Www.glassdoor.com/foo/bar/joBs
    - http://192.168.1.1/ABC/job
    - http://bankers.jobs/ABC/job

My decision to use lookaheadand lookbehind, . This works well in the above lists. However, if the URL is , it will not work. /(?<!\.)job(?!\.)/iHTTPs://jobs.com/test

I am wondering what is the correct answer to this question. Thanks in advance for any suggestions!

+4
source share
4 answers

Try this regex:

/\b(?:https?:\/\/)?[^\/:]+\/.*?job/gmi

Online Demo: http://regex101.com/r/rV3oP8

+2
source

URL-, ""

 #  /(?i)(?<=\/)job(?=\/|[^\S\r\n]*$)/

 (?i)
 (?<= / )
 job
 (?= / | [^\S\r\n]* $ )
+2

:

^(?:.*://)?(?:[wW]{3}\.)?([^:/])*/.*job.*

, , job.com jobs.com. ( .)

, b/c, regex .

+1

, : /./+job/?./i Rubular.com

0

Source: https://habr.com/ru/post/1524111/


All Articles