Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I expand this regex match to the left http(s) to match the entire URL?

I’m using the regex \/s1600-h\/[^\/\s'"]+ to match URLs with the directory of /s1600-h/ in an URL, i.e.

http://localhost/wpcomics/wp-content/images/_Tkt_A2r1p6I/RlcBEI/AAAAEU/D630/s1600-h/tedsobject.jpg

and that matches from /s1600-h/ to the right and includes the file and extension.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

enter image description here

But how can I expand the match to the left to match the entire URL? No matter the number of subdirectories? And either http or https?

Here’s a fiddle: https://regex101.com/r/agB4iJ/1

>Solution :

If you don’t care about valid URL and just want to match the line containing that path, then simply prepend .+

.+\/s1600-h\/[^\/\s'"]+
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading