Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
Suppose i have below Json String:
{
"name":"noor",
"pass":"12345"
}
I want to mask pass value using Regex, like below
{
"name":"noor",
"pass":"*****"
}
How i can do it, using Java regex?
Try this:
"pass":"(.*?)"
As seen on: https://regex101.com/r/cK4bD0/1
try this
String jsonString = "{ \"name\":\"noor\", \"pass\":\"12345\" }";
String result = jsonString.replaceAll("(?<=pass\":\")(.*?)(?=\")", "*****");
System.out.println(result);
{[^}]*"pass"\s*:\s*"(.*?)"[^}]*}
Here is the DEMO: https://regex101.com/r/nL3tP2/2
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How do I get the after last two semicolon's occurrences of a string ?
Example:
Mobiles;Students;Test;Yes;1234
The output should be
Yes;1234
Using a regex replacement, we can try:
String input = "Mobiles;Students;Test;Yes;1234";
String output = input.replaceAll("^.*;([^;]+;[^;]+)$", "$1");
System.out.println(output); // Yes;1234
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
I want to return back a Arraylist of string which contains userName in the response with the response code 200. How to implement this.Thanks in advance.
ResponseEntity<List<String>> someMethod() {
List<String> userNames = getvalues();
return new ResponseEntity<>(userNames, OK);
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Suppose we have a string BE231231.
I need an output like this : BE0231231
need to append zero at a this fixed location in java inside a method
public String appendAtIndex(String base, String toAppend, int index){
return base.substring(0,index) + toAppend + base.substring(index);
}
You can implement the logic for restrictions on index accordingly so that base.substring does not give errors.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have JSON response from server. JSON has exception info inside of it.
I need to parse it to detect that exception occurred and identify which one.
JSON example:
I found the solution to what I need
Pattern errorCodePattern = Pattern.compile("\"code\"\\s*:\\s*\"([^,]*)\",");
Pattern messagePattern = Pattern.compile("\"message\"\\s*:\\s*\"([^,]*)\",");
Pattern statusPattern = Pattern.compile("\"status\"\\s*:\\s*\"(FAILURE)\"");
Matcher errorCodeMatcher = errorCodePattern.matcher(response);
Matcher messageMatcher = messagePattern.matcher(response);
Matcher statusMatcher = statusPattern.matcher(response);
Java JSON Parser Example with Regex
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have this text:
1 A Maths
And i would like to get only Maths.
I donĀ“t know about regular expressions.
Can any one help me, please?
Thanks
Why don't you split the string ?
String chain="A Maths";
String[] array=chain.split(" ");
String number=array[0];
String course=array[1];
...
How to split a string in Java