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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T05:50:15+00:00 2026-06-14T05:50:15+00:00

This is my original String named ‘response’: String response = attributes[{displayName:Joe Smith,fact:super},{displayName:Kieron Kindle,fact:this is

  • 0

This is my original String named ‘response’:

String response = "attributes[{"displayName":"Joe Smith","fact":"super"},{"displayName":"Kieron Kindle","fact":"this is great"}]";

I’m trying to parse the String and extract all the id values e.g

String[0] = Joe Smith
String[1] = Kieron Kindle

Pattern idPattern = Pattern.compile("\"displayName\":(\\w)"); // regular expression
Matcher matcher = idPattern.matcher(response);

while(matcher.find()){
    System.out.println(matcher.group(1));
}

When i try to print the value nothing is printed to screen (no exception)
the regex expression looks for "displayName":" as a left bracket and " as right bracket then extracts any words (\\w) between them?
Appreciate any help!
Removed the \n characters from my regex, that was a formating mistake, sorry guys!

  • 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-14T05:50:17+00:00Added an answer on June 14, 2026 at 5:50 am

    But why have you used a \n in your regex? That should be \". Also you have used \\w which matches just a single character. You need to use a quantifier with that. And a Reluctant one.

    So, your modified regex is like this: –

    Pattern.compile("\"displayName\":\"(\\w+?)\""); // This won't consider space
    

    But, since your String can also contain space, so you should not use \\w. It will not match a space.

    So, finally, you should use this regex, which matches any character in between two inverted commas, except inverted comma itself: –

    Pattern.compile("\"displayName\":\"([^\"]+)\"");
    

    With the above pattern substituted in your code, your output would be like this: –

    "Joe Smith"
    "Kieron Kindle"
    

    You can read more about Regex in these tutorials: –

    • http://docs.oracle.com/javase/tutorial/essential/regex/
    • http://www.vogella.com/articles/JavaRegularExpressions/article.html
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

String product = Integer.toString(w); char[] original = String.toCharArray(product); This is the code I have
I have this original formula from a medical research book: Log(e) (EFW) = (-4.564+(0.282*AC)-(0.00331*AC^2))*1000
I got the JSON from apple like this { original-purchase-date-pst = 2012-06-28 02:46:02 America/Los_Angeles;
This is a continuation of this question: Original Question (SO) The answer to this
I'm curious why is method fillInStackTrace of java.lang.Throwable public? This method replaces original stack
This is a slightly original variation on a common problem. I have a fairly
this is an edit of the original post now that I better understand the
Original SQL query is this; SELECT id,post_title,post_date FROM wp_posts where id='1' When I retrieve
This is what my .htaccess file looks like: # Original # If you modify
from this code will show in original color how can i change it to

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.