I am trying to parse the string to get the Record name which is auto number D-{0000} format (ex: D-345677) and record id which is 15 to 18 char length which prefix starts with(a7s7) and full id is 'a7S7j00000011qaEAA' format (a7S+anycharacterornumber). The char of Id is 15 or 18 long
So for I tried this
string str = 'This is a design number D-123989 and Id is a7S7j00000011qaEAA and 90090';
Pattern p1 = Pattern.compile('a7S([a-zA-Z0-9]{12,15})');
Pattern p = Pattern.compile('D-([0-9]+)');
Matcher pm = p.matcher(str);
Matcher pm1 = p1.matcher(str);
string res;
if (pm.find()) {
res = 'match = ' + pm.group(1);
System.debug(res); //It should give D-123989 but giving 123989
} else {
System.debug('No match');
}
if (pm1.find()) {
res = 'match = ' + pm1.group(1); //It should give a7S7j00000011qaEAA but not matching
System.debug(res);
} else {
System.debug('No match');
}
The first one is a success and it's returning 123989 instead of D-123989 and the second one Id matching is not working. Need help here!
D-[0-9]+
should work.