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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T06:02:45+00:00 2026-06-15T06:02:45+00:00

String pw=pw:(abc);//Maybe pw:(12),pw:(ab123)… pw=pw.replaceFirst(\\(.+\\), *); //pw == result:pw:* I want the results: pw:***** .

  • 0
String pw="pw:(abc)";//Maybe "pw:(12)","pw:(ab123)"...
pw=pw.replaceFirst("\\(.+\\)", "*");

//pw == result:pw:*

I want the results: pw:*****. (abc) must be * x 5

Asterisk in quantities equal to the length of the content is matched

Can I use String.replaceFirst or String.replaceAll only way to implementing it?

  • 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-15T06:02:47+00:00Added an answer on June 15, 2026 at 6:02 am

    You can do this:

    final String pw = "pw:(abc)";
    
    final String anon = pw.replaceAll("[^pw:]", "*");
    
    System.out.println(pw);
    System.out.println(anon);
    

    which will result in:

    pw:(abc)
    pw:*****
    

    Edit: does not work if the password has p/w/: in it… will try to fix..

    Edit #2: This turned out to be harder than I thought, had to go with another approach:

        final String input = "pw:(abc) something!";
    
        Matcher matcher = Pattern.compile("\\(.*\\)").matcher(input);
    
        if (matcher.find()) {
            final String onlyPw = matcher.group();
            final String stars = StringUtils.repeat("*", onlyPw.length());
    
            System.out.println(input.replace(onlyPw, stars));
        }
    

    So, first find the String consisting of “({something})”. Then create a String consisting of the number of stars in this string. Then replace the string with the stars in the input.

    Note: This does not work if the password or the text after the ) contains parantheses, but then again I doubt you will find a regex that does..

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

Sidebar

Related Questions

i have an old string say oldString=abc-2 i want to change it to abc-3
string abc = 07:00 - 19:00 x = int.Parse(only first two characters) // should
String abc[]={abc}; String def[]={}; def=abc; def[0]=def[0]+changed; System.out.println(abc[0]); by changing def object, my abc object
Consider statement: String s=new String(abc); Will this statement creates two String objects namely abc
how could I trim and convert a string as following: string abc = 15k34
I have the following string (the double quotes are part of the string): abc
As far as I know, in Java I can Object o = new String(abc)
(LocalVariable)ABC.string(Name) = (IDataReader)dataReader.GetString(0); This name value is coming from database. What happening here is
In a string like abc fox fox fox ghi xyz how can i get
need help to create regular expression matching string www.*.abc.*/somestring Here * is wild card

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.