Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8962913
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:14:32+00:00 2026-06-15T16:14:32+00:00

So a Regex pro I am not, and I’m looking for a good way

  • 0

So a Regex pro I am not, and I’m looking for a good way to do this. I have a large string which contains a variable number <img> tags. I need to change the path on all of these images to images/. The large string also contains other stuff not just these img’s.

<img src='http://server.com/stuff1/img1.jpg' />
<img src='http://server.com/stuff2/img2.png' />

Replacing the server name with a ReplaceAll() I could do, it’s the variable path in the middle I’m clueless on how to include. It doesn’t necessarily need to be a regex, but looping through the entire string just seems wasteful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T16:14:33+00:00Added an answer on June 15, 2026 at 4:14 pm

    The following should work for replacing all <img> tags that link to a jpg from server.com:

    s.replaceAll("<img src='http://server.com[^']*/([^']*)' />", "<img src='images/$1' />");
    

    If you are using double quotes around the src property:

    s.replaceAll("<img src=\"http://server.com[^\"]*/([^\"]*)\" />", "<img src=\"images/$1\" />");
    

    This works because [^']*/ will match as many characters that are not single quotes as possible, and then a literal ‘/’, so it will consume the entire path. If all <img> tags are from server.com you can remove http://server.com and the regex will work the same way.

    Note that you can shorten this even more if you know in advance that all of the image tags need to be replaced, or if your string only consists of <img> tags, for example you could use the following to just replace the path in all src properties:

    s.replaceAll("src='[^']*/([^']*)'", "src='images/$1'");
    

    Just add more of the literal strings you want to match to the regex if this replaces more than you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm not a pro in Regex, therefore I'm having a difficulty translating this regex
Any regex gurus around here? its driving me crazy. Say I have this string:
Simple regex question. I have a string on the following format: this is a
Regex Expression for finding a string which has one @ and should not start
My regex at the minute is like this '/[a-z0-9]{40}/i' Which will match any string
RegEx has always confused me. I have a string like this: IDE\DiskDJ205GA20_____________________________A3VS____\5&1003ca0&0&0.0.0 Or Sometimes
Regex is not really my thing. But i have this in my php file
Regex rx = new Regex(@[+-]); string[] substrings = rx.Split(expression); expression = -9a3dcbh-3bca-4ab4cf-3hc //This is
Regex rx = new Regex(@(?<!\\\\),); String test = OU=James\\, Brown,OU=Test,DC=Internal,DC=Net; This works perfectly, but
This regex below captures the -aaaa and -cccc but not the -eee How can

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.