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 7880771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T04:13:27+00:00 2026-06-03T04:13:27+00:00

I do not understand regular expressions. I need to change an img tag formatted

  • 0

I do not understand regular expressions. I need to change an img tag formatted in this manner: <img class="special-class" (then custom srcs and whatever) />. I figure preg_replace would do the job or would there be something more effective?

I just need the regular expression way to search for the full img tag with that first class so i can replace it with another string saved as $buzz

  • 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-03T04:13:28+00:00Added an answer on June 3, 2026 at 4:13 am

    To match a full img tag (with valid html and no unquoted > in there):

    preg_match('#<img([^>]+)>#i', $html, $match);
    

    Don’t know what else you want…

    $match will contain the full in [0] and the attributes (as string) in [1].

    If you want to match the class attribute:

    preg_match('#class="([^"])"#i', $html, $match);
    

    edit
    Huh this might work:

    preg_replace('#<img[^>]+class="[^"]*replace[^"]*"[^>]*>#', '', $html);
    

    If I input:

    <img src="oele" class="boele" />
    <img src="boele" />
    <img src class="replace boele">
    

    it only replaces the last img and leaves the rest untouched.

    Regex rules!

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

Sidebar

Related Questions

I'm not new to using regular expressions, and I understand the basic theory they're
I'm not very knowledgeable with regular expresions, so I don't understand why I'm getting
I simply do not understand why both works: this.timer.Tick += new EventHandler(timer_Tick); this.timer.Tick +=
I do not understand this error, do not generate error in JsonResult Test (),
I do not understand how the DefaultProperty Metadata tag work or what it signifies.
I do not understand what is wrong with this query? Query tool does not
First yes, this is a homework project for my Perl class. I am not
I'm not sure how to accomplish this with a regular expression (or if I
I need a library which will take in two regular expressions and determine whether
I am not new to regular expressions and I use them all the time.

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.