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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:17:45+00:00 2026-05-28T15:17:45+00:00

I am using a Matcher to find specific patterns in a String that contains

  • 0

I am using a Matcher to find specific patterns in a String that contains a text.
The regular expression checks for various patterns e.g. for simplicity:
\\bword1\\b|(\\b(?:word2(?:(\\s+)word3)?)?) etc

Anyway I can find the patterns in the string.
So far ok.

What I want though, is to be able to use the Matcher.replaceAll in order to replace each pattern found, with the same pattern but with some addition.

E.g.

If the matcher finds word1 somewhere, I want to replace it with {v}word1{v}.

How is this best done?I tried to add the groups that matcher finds in a list and then loop over the input string to replace all but obviously this did not work.

UPDATE:
I can match the terms I need and @Luis regex does the replace, but I need to replace all in my String.
By looping and doing the regex "pattern", "{v}$0{v}") inside the string I break previous occurences I made. I need to somehow include a negative lookbehind in the replaceAll so as to understand when a term has already been replaced

UPDATE:
Using @Luis regex and negative lookbehind it worked

  • 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-28T15:17:47+00:00Added an answer on May 28, 2026 at 3:17 pm

    UPDATED:

    "pattern".replaceAll("pattern", "{v}$0{v}"))

    I’ve tested this and it returns “{v}pattern{v}” as desired.

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

Sidebar

Related Questions

I need to use a regular expression that contains all the \b characters except
I am trying to obtain the string that my matcher is able to find
Trying to write a code that searches hash values for specific string's (input by
I am using while(matcher.find()) to loop through and retrieve things from a file. I
How would I go about using a negative lookbehind(or any other method) regular expression
I've been using http://www.regexplanet.com/advanced/java/index.html to test a regular expression I've written. The regular expression
I'm using JavaScript to set the value of an input with text that may
I need to find whole words in a sentence, but without using regular expressions.
I am using a while(matcher.find()) to loop through all of the matches of a
I'm using the Java matcher to try and match the following: @tag TYPE_WITH_POSSIBLE_SUBTYPE -PARNAME1=PARVALUE1

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.