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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T00:49:09+00:00 2026-06-13T00:49:09+00:00

I just found this method inside a Utils-type class in our codebase. It was

  • 0

I just found this method inside a “Utils”-type class in our codebase. It was written a long time ago by a developer who no longer works for us. What in tarnation is it doing? What is it returning?!? Of course, there’s no JavaDocs or comments.

public static String stripChars(String toChar, String ptn){
    String stripped = "";
    stripped = toChar.replaceAll(ptn, "$1");
    return stripped.trim();
}

Thanks in advance!

  • 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-13T00:49:10+00:00Added an answer on June 13, 2026 at 12:49 am

    It seems to replace everything in “toChar” which matches the regular expression “ptn” with the first group to match in “toChar”

    Regular expressions have a concept of groups, for example matching “year 2012” and replacing it with “year 1012”, or “year 2006” with “year 1007” (changing the first 20 to 10) can be accomplished by replacing

    “year 20([0-9][9-9])” with “year 20$1” — That is, match the entire string, and then replace it “year 20” followed by the first group ($1). The group is the first thing in parenthesis.

    Anyway, your method then replaces everything that matches “ptn” in “toChar” with the first group in the regular expression “ptn”. So given
    stripChars(“year 2012”, “year 20([0-9][9-9]”); You would receive back only “12” because the entire text would match and be replaced by only the first group.

    It then trips any leading or trailing whitespace.

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

Sidebar

Related Questions

I was just reading this post When is IHttpModule.Dispose method called? I found this
I just found this : a = (None,) print (a is True) print (a
I just found this project which provides a way of running Google App Engine
I just found this code in reflector in the .NET base libraries... if (this._PasswordStrengthRegularExpression
I have just found this great tutorial as it is something that I need.
I just found out this weird behavior, is this a bug or what am
I just found my code like this does not compile right? Is there any
I just recently found myself writing this line of code, which i did not
I just started a new Typo3 4.6 site and I found this weird line
i use this code in my app. just found is not correct when compare

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.