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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T09:43:28+00:00 2026-05-20T09:43:28+00:00

I want to strip a SOAP envelope from a message to get at the

  • 0

I want to strip a SOAP envelope from a message to get at the XML in the body.

I attempted the following;

String strippedOfEnvelopedHeader = msg.replaceAll("(?s)(?i)<(.*):Envelope.*<\1:Body>", "");

I thought that this would stip out the SOAP envelope, specifically the header, from a message like;


<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'>
<env:Header xmlns:env='http://schemas.xmlsoap.org/soap/envelope/' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'/>
<soapenv:Body>
<myXML> stuff is here</myXML>
</soapenv:Body>
</soapenv:Envelope>

which should result in;


<myXML> stuff is here</myXML>
</soapenv:Body>
</soapenv:Envelope>

However, the group back-reference does not seem to work.

If I replace both the capture group and the back-reference the substitution works fine;

String strippedOfEnvelopeHeader = msg.replaceAll("(?i)(?s)<soapenv:Envelope.*<soapenv:Body>", "");

I think I can guess the problem, the capture group is being greedy and grabbing the entire message and thus failing the match.

But the solution evades me.

Any ideas?

  • 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-05-20T09:43:29+00:00Added an answer on May 20, 2026 at 9:43 am

    Try 2 backslashes

    "(?si)<(.*):Envelope.*<\\1:Body>"
    

    You need 2 because \1 itself is already a special escape sequence to Java. Therefore it will be decoded into the character U+0001 before feeding to the regex engine. You need to protect it by adding one more backslash.

    (And the usual “don’t parse XML with Regex” warning follows…)

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

Sidebar

Related Questions

I want to strip all html tags from a string except some I specify.
Following How to get folder path from file path with CMD I want to
I want to strip whole words from a string wherever they are inside the
I want to strip the following out of a string: http:// https:// www. www2.
I want to strip out <p> and </p> from a string (lets say s
I want to strip the extension from a filename, and get the file name
I have a list of words I want to strip from a string. I
i want to strip all the html tags from a string except ( <img>
I want to strip all non-alphanumeric characters EXCEPT the hyphen from a string (python).
I want to be able to strip off a header from a wav file.

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.