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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:55:37+00:00 2026-06-13T09:55:37+00:00

I have below message String. I want to replace all the image tag which

  • 0

I have below message String. I want to replace all the image tag which contains the occurence of sequence i.e ?custId=1234 with new string cid:

 String message = "Need to process  image tag <img src=\"http://danny.oz.au/p/56214815-tripod.jpg?custId=1234\"/>";

This what i tried after going thru bit of regex tutorial which replaces all image tag occurence with cid:. I am not getting how to fit the
one more filter i.e ?custId=1234 in regex so that replace only those image tags that contains ?custId=1234

  message = message.replaceAll("\\<img.*?>", "cid:");

EDIT:- For example if
input is

  "Need to process  image tag <img src=\"http://danny.oz.au/p/56214815-tripod.jpg?custId=1234\"/>";

output should be
“Need to process image tag cid:”;

becoz input contains img tag and ?custId=1234 both

input is

     "Need to process  image tag <img src=\"http://danny.oz.au/p/56214815-tripod.jpg?custId=1235\"/>";

output should be

     "Need to process  image tag <img src=\"http://danny.oz.au/p/56214815-tripod.jpg?custId=1235\"/>";

becoz input does not contain ?custId=1234 both

  • 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-13T09:55:38+00:00Added an answer on June 13, 2026 at 9:55 am

    Try this: –

    message = message.replaceAll("<img.*?\\?custId=1234.*?>", "cid:");
    

    For your given input string: –

    "Need to process  image tag <img src=\"http://danny.oz.au/p/56214815-tripod.jpg?"
    + "custId=1234\"/>"
    

    this will give you: –

    "Need to process  image tag cid:"
    

    Also for input: –

    "Need to process  image tag <img src=\"http://danny.oz.au/p/56214815-tripod.jpg?custId=1235\"/>"
    

    OUTPUT: –

    "Need to process  image tag <img src=\"http://danny.oz.au/p/56214815-tripod.jpg?custId=1235\"/>"
    

    Also, I would suggest you to take a look at Jsoup - Java HTML Parser, which you should use to parse your HTML. Regex is not a good idea to parse HTML. You can only parse a limited range of tags.

    You can also use HTML Cleaner


    UPDATE: –

    If you want your dot (.) to match newline also, you can use PAttern.DOTALL flag. Alternativey, in case of String.replaceAll(), you can add a (?s) at the start of the pattern, which is equivalent to this flag.

    From the Pattern.DOTALL – JavaDoc : –

    Dotall mode can also be enabled via the embedded flag expression (?s).
    (The s is a mnemonic for “single-line” mode, which is what this is
    called in Perl.)

    So, you can modify your pattern like this: –

    message = message.replaceAll("(?s)<img.*?\\?custId=1234.*?>", "cid:");
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string which has say 3000 characters, now I want to split
I have below query I am trying to show message 'No SubSource for this
I have a SOAP message (see below). Using Xpath, how can I extract the
I have a script snippet looks like below: <ItemGroup> <files Include=*.txt></files> </ItemGroup> <Message Text=@(files)>
I have below snippet of code in which TestClass is extending jPanel which is
I have below code: class Program { static void Main(string[] args) { Task[] tasks
I have below string String str=select * from m_menus; select * from m_roles; I
I want to have a message send & receive through 2 uni-direction FIFO Flow
i want to use below codes. So i have a generic list<MyClass> i think
Here i have a string which is split and each line is in a

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.