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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T07:45:49+00:00 2026-06-02T07:45:49+00:00

I need replace multiline string in file, like this: startString bla bla bla …

  • 0

I need replace multiline string in file, like this:

startString
bla bla bla
...
endString

by ant replaceregex.
Ant code:

    <copy file="${file}" tofile="${newFile}" overwrite="true">
        <filterchain>
            <replaceregex pattern="startString(.+)endString" replace="zzz" flags="gmi" byline="true"/>
        </filterchain>      
    </copy>

If text for replace is Single line – all works correct, but when text is multiline – replaceregex doesn’t work.
What I should fix in my code?

  • 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-02T07:45:51+00:00Added an answer on June 2, 2026 at 7:45 am

    There are a couple of changes you need to do. There are a couple of settings you had suggesting that each line of input should be considered a separate line of input which are the byline attribute and the m flag. In the following I have removed those and also added the s flag which treats the input file a single line of input:

    <replaceregex pattern="startString(.+?)endString" replace="zzz"
        flags="gis" byline="false"/>
    

    Also note the addition of the ? in the regex, this makes the wildcard non greedy in case you have multiple occurrences you want to match.

    See

    The ant ReplaceRegExp documentation for more.

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

Sidebar

Related Questions

I need to replace special characters from a string, like this: this.value = this.value.replace(/\n/g,'');
I need to replace a string like 123456 to ,123456 . I tried this.
I have a string. In this string i need replace all special characters (0-31
I need to replace a simple string in a minified .js file after a
I've got a multiline string like this. Ity has line feeds. [Site Url=http://medportal.domain.edu Owner=DOMAIN\user1
I need to replace many different sub-string in a string in the most efficient
I need to replace all System.Environment.Newline(s) in the string returned by my function with
I need to replace some text in a JNLP file using a DOS batch
I need to replace accented characters in a string with their unaccented counterparts and
I need to replace wrong symbols except chars and digits in my string with

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.