Regex expression to find images

Hi All.

Silly questions, but going to ask it, notwithstanding.

I need to find all of the images on one of my websites so I can migrate it. (Lost alot of the originals when my computer expired).

I have got a regex that works 99% but am having an issue where when I look for the final “.jpg” it fails.
The online regex courses say what I am doing is correct, but I think the difference is that the url return is a mass of text with no real “end of lines” so I can use the $ anchor for the end

Here is my regex string so far:
http(s)://[a-zA-Z0-9].{70}

How do I do the end jpg… or bmp… or gif (you get the general idea).

Regards

It would help if you showed one of the lines that failed …

no problem! Happy to oblige

https://www.michaelcebasek.com/homepage/aboutMe/uploads/1998/10/myLocationMap.jpg?

It is nested in a ton of gibberish, so I just selected the line. If you want the gibberish, let me know and you can have that too!

Regards

Try this instead

http(s)?://[a-zA-Z0-9]\.(jpeg|jpg|png|gif)

Not at my computer but how do you expect your RegEx to find this if you don’t include the “/“?

http(s)?://[a-zA-Z0-9\/\.\_]*\.(jpeg|jpg|png|gif)

On my computer now and have tested it in RegExRX - my RegEx works.

Btw I highly recommend RegExRX (by “Mr. RexEx” Kem Tekiney himself) if you use RegEx more than just once or twice.

Good point. But I don’t think you need to escape the ones inside the square brackets.

(Where’s @Kem_Tekinay )

True. This is enough:

http(s)?://[a-zA-Z0-9/._]*.(jpeg|jpg|png|gif)

Hi Markus.

Yes I got the RegExRX software, and I built the regex string with it. It seemed to work within the program but when I went and tested with the page as data, it never quite worked.

I am very grateful for the program, but it can’t fix human errors… (grin)

I’ll give this a try and it you don’t hear back from me, “No news is good news”.

Regards

Sorry guys. That Regex didn’t work.

Regards

To be honest, I doubt that. I rather suspect a copy/paste error.

Tip: if you want help, then put in the effort to give the required information and ideally an example project.

If you do NOT put in the effort, then please don’t expect others to do it for you.

So I am out now as I find it rather annoying to just get tidbits all the time rather than actionable information.

@Michael_Cebasek

Let’s get some info from you:

Give us some examples of what your html looks like, what you are expecting to get out and the full reflex code you are using.

Hi Markus.

I NEVER expect anyone to do my work.
In the real world this happens to me all the time and I don’t like it either. :smile:

I will try again, and this is what I have copied:
http(s)?://[a-zA-Z0-9/._]

I will try again and advise.

Have a great day and thank you for all of your help so far!

Regards

If you aren’t interested in validation, just matching, I’d suggest something simpler:

\bhttps?://\S+

If you are looking specifically for certain image files, then:

\bhttps?://\S+\.(jpe?g|bmp|png)\b
2 Likes
Forum for Xojo Programming Language and IDE. Copyright © 2021 Xojo, Inc.