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

  • Home
  • SEARCH
  • 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 7780699
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:59:07+00:00 2026-06-01T18:59:07+00:00

<img[^>]+src\\s*=\\s*[‘\]([^’\]+)[‘\][^>]*> I know this regex expression is used to retrieve the value of src.

  • 0
<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>

I know this regex expression is used to retrieve the value of src. Can anyone teach me how i should interpret this expression? stucked at it.

  • 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-01T18:59:10+00:00Added an answer on June 1, 2026 at 6:59 pm

    Explaining:

    • <img matches exactly the string "<img"
    • [^>]+ matches multiple times of everything but >, so the tag will not be closed
    • src matches exactly the string “src”
    • \\s* matches any number of whitespace characters
    • = matches exactly the string “=”
    • \\s* matches any number of whitespace characters
    • ['\"] matches the two quotes. The double quote is escaped, because otherwise it will terminate the string of the regex
    • ([^'\"]+) mathches multiple times everything but quotes. The contents are wrapped in brackets, so that they are declared as group and can be retrieved later
    • ['\"] matches the two quotes. The double quote is escaped, because otherwise it will terminate the string of the regex
    • [^>]* matches the remaining non ">" characters
    • > matches exactly the string ">", the closing bracket of the tag.

    I would not agree this expression is a crap, just a bit complex.

    EDIT Here you go some examplary code:

    String str = "<img[^>]+src\\s*=\\s*['\"]([^'\"]+)['\"][^>]*>";
    String text = "<img alt=\"booo\" src=\"image.jpg\"/>";
    Pattern pattern = Pattern.compile (str);
    Matcher matcher = pattern.matcher (text);
    
    if (matcher.matches ())
    {
          int n = matcher.groupCount ();
          for (int i = 0; i <= n; ++i)
              System.out.println (matcher.group (i));
    }
    

    The output is:

    <img alt="booo" src="image.jpg"/>
    image.jpg
    

    So matcher.group(1) returns what you want. experiment a bit with this code.

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

Sidebar

Related Questions

I used this regex expression to search for img src in a string in
If I write something like this: var img = $(new Image()).attr('src', image.src); How can
I need a regular expression that can match any url in img src tag
I have this regex in JavaScript: var val = val.replace(/[:)]/g, <img src = \/img/smile.png\
If my div container has this: <div id=container><img src... I can style the image
I need to process a HTML content and replace the IMG SRC value with
How do I match an URL string like this: img src = https://stackoverflow.com/a/b/c/d/someimage.jpg where
Lets say that i have img tag like this, <img src = myimage.jpg width
Look at this situation: www.websitea.com displays an img tag with a src attribute of
Possible Duplicate: Regex to change format of all img src attributes Hi, I want

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.