Help needed with Regular Expression pattern

J

John

Can anyone help?

I need to search for a string such as 'images/filename.ext'
where filename is unknown in advance and ext can be either jpg, gif or bmp

Can anyone help me by providing a regular expression 'pattern' to match this criteria?

Do I make sense?

TIA
 
B

belafazekas

One pattern is:

^images/.*\.(jpg|gif|bmp)$

Meaning:

^ = begin of path, no character before (if needed)
..* = any character repeated any times
\. = the dot character
(jpg|gif|bmp) = the extension
$ = end of path, no more character(if needed)

If you vant to search in html file, for example to find <IMG="images/1.jpg">
etc.
use " instead of ^ and $
 
J

John

Many thanks
If I remove the beginning carat and the ending dollar characters, then the pattern works...but only
if there are none found or no more than 1 occurance found.
If there is more than 1, then along with the name of the first occurance, the remaining text in the
searched string upto the last occurance is also shown.

Any ideas?
TIA
 
A

Andrew Murray

Generally the "wildcard" (the asterisk - '*') character finds anything in
common withevery file eg. *.jpg will find all jpg files or all JPG files
starting with letter 'a', such as a*.jpg ; or all (any) file(s) starting
with letter 'a' as in : a*.*

Is that what you mean?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top