Thursday, 20 December 2018

Java Regular Expression to fetch last three characters of String

import java.util.regex.Matcher;

import java.util.regex.Pattern;



public class RegExp {

 
public static void main(String[] args) {

 
String instanceName = "pod3cgs02";

Pattern digitPattern = Pattern.compile("\\d{2}$");

Matcher matcher = digitPattern.matcher(instanceName);
System.out.println(digitPattern.matcher(instanceName).matches());

 
if (matcher.find()) {

System.out.println("find() found substring \"" + matcher.group()

+ "\" starting at index " + matcher.start()

+ " and ending at index " + matcher.end());

}

 
}

}

No comments:

Post a Comment

Pass a HashMap from Angular Client to Spring boot API

This example is for the case where fileData is very huge and in json format   let map = new Map<string, string>()      map.set(this.ge...