I have 1K strings like the following which are saved in a String array and I just need the bold words, which are not a constant)’. So wondering what could be the best way.
(descSummary: EME Commercial (Change Request), archived: false, name: EME Commercial (Change Request), uniqueName: EME Commercial (Change Request)(JTS-Sentinel-Id)) (isInitialized: true, internalPublic: true, internalVisibleToMembers: false, internalVisibleToAccessList: false, owningApplicationKey: JTS-Sentinel-Id, internalIsProcessProvider: false)
Please help!
Well, it looks like you are asking for the text after the string “name: ” and before the following comma, so your regex is
/name: ([^,]+)/Update:
I don’t understand why you’re using
.replaceAll().You don’t need the slashes to delimit the regex when it’s in a Java string literal. Many people, like me, use the slashes to set it off in ordinary text.
If you want to display the segment you have marked in bold, then you want something like this:
.group(0)returns the entire string that matched the pattern..group(1)returns the string that matches the first “captured” group in parentheses, the([^,]+)part.And why are you calling
.toString()onstr? The name of that variable suggests that it is a String already.