regex for all numbers code example
Example 1: regex for numbers
Regex regex = new Regex(@"^\d$");
Example 2: regex to get all numbers in a string
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Just {
public static void main(String[] args) {
String data = "abc12def334hjdsk7438dbds3y388";
String regex = "([0-9]+)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(data);
System.out.println("Digits in the given string are: ");
while(matcher.find()) {
System.out.print(matcher.group()+" ");
}
}
}