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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:31:22+00:00 2026-05-14T18:31:22+00:00

Problem: Turn My Testtext TARGETSTRING My Testtext into My Testtext targetstring My Testtext Perl

  • 0

Problem: Turn

"My Testtext TARGETSTRING My Testtext" 

into

"My Testtext targetstring My Testtext"

Perl supports the “\L”-operation which can be used in the replacement-string.

The Pattern-Class does not support this operation:

Perl constructs not supported by this class:
[…]
The preprocessing operations \l \u, \L, and \U.
https://docs.oracle.com/javase/10/docs/api/java/util/regex/Pattern.html

  • 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-14T18:31:23+00:00Added an answer on May 14, 2026 at 6:31 pm

    You can’t do this in Java regex. You’d have to manually post-process using String.toUpperCase() and toLowerCase() instead.

    Here’s an example of how you use regex to find and capitalize words of length at least 3 in a sentence

        String text = "no way oh my god it cannot be";
        Matcher m = Pattern.compile("\\b\\w{3,}\\b").matcher(text);
    
        StringBuilder sb = new StringBuilder();
        int last = 0;
        while (m.find()) {
            sb.append(text.substring(last, m.start()));
            sb.append(m.group(0).toUpperCase());
            last = m.end();
        }
        sb.append(text.substring(last));
    
        System.out.println(sb.toString());
        // prints "no WAY oh my GOD it CANNOT be"
    

    Note on appendReplacement and appendTail

    Note that the above solution uses substring and manages a tail index, etc. In fact, you can go without these if you use Matcher.appendReplacement and appendTail.

        StringBuffer sb = new StringBuffer();
        while (m.find()) {
            m.appendReplacement(sb, m.group().toUpperCase());
        }
        m.appendTail(sb);
    

    Note how sb is now a StringBuffer instead of StringBuilder. Until Matcher provides StringBuilder overloads, you’re stuck with the slower StringBuffer if you want to use these methods.

    It’s up to you whether the trade-off in less efficiency for higher readability is worth it or not.

    See also

    • StringBuilder and StringBuffer in Java
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Ive got a problem that if I have a template class, which in turn
I am having a little problem how can I turn the following code into
I have a problem trying to turn my python code into an executable using
When in doubt, turn to Stackoverflow... I'm having a problem with string allocation. My
I'm using the header() function to turn a file into XML standard. The problem
I want to turn a program I have into a service so I can
Problem : How can I get a successful TURN Connection using the iOS XMPPFramework
Apologize if this particular problem has been answered already (a search didn't turn anything
Problem: I've written State Machine for my android application. It is separate class, extension
I am facing problem that whenever I turn off security settings in IE8, in

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.