I try to extract 7 numbers (a contract number) out of a random string using regex:
pattern contractNumberPattern = pattern.compile('[0-9]{7}');
Matcher contractNumberMatcher = contractNumberPattern.matcher('Test1234567Test');
String contractNumber;
system.debug(contractNumberMatcher.find());
system.debug(contractNumberMatcher.matches());
system.debug(contractNumberMatcher.groupCount());
system.debug(contractNumberMatcher.group());
contractNumber = contractNumberMatcher.group(0);
system.debug(contractNumber);
Unfortunately this does not bring the desired result. the find() returns true but the groups are empty.
I tested my regex on a regex tester site and it bringt the right result. So ... where am I wrong?
Thanks and best, Markus