1

For my Java app, i have a string that looks like:

value1: *sample", test
test: "test"
newtest: *newtest"

I need to match the character " when the string starts with *.
Tried the regex: "(?!.*") But this selected all the " in the input.
Was planning to replaceAll(regex, "") to remove the character.

Desired Output:

value1: *sample, test
test: "test"
newtest: *newtest

How do i get this output?

2
  • 3
    Try .replaceAll("(\\*\\w+)\"", "$1") Commented Jan 20, 2023 at 17:33
  • 1
    This worked, Thanks. I can see that you are matching the word starting with * and ending with ", how did the " get replaced? Commented Jan 20, 2023 at 17:40

1 Answer 1

1

You can use

.replaceAll("(\\*\\w+)\"", "$1")

Details:

  • (\*\w+) - Group 1 ($1 refers to the text captured in this group)
  • " - a " char (just matched, not captured, so eventually removed).
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.