I am trying to find a regular expression to remove specific letters from the beginning of a string. For example, first occurrence of letter P should be removed like:
P1234 -> 1234
A1234 -> A1234
ABCD -> ABCD
PP5678 -> P5678
I tried to use several expressions, one of them being [^P{1}](.*)$
but everything I tried was removing also the 2nd occurrence of P in PP5678 and I got as result 5678 instead of P5678.
Is there any way to eliminate only first occurrence of letter P?
L.E.: the code that does the replacement looks like this:
Pattern dataPattern = Pattern.compile(dataFormat);
Matcher dataMatcher = dataPattern.matcher(barcode);
if (dataMatcher.find()) {
fieldValue = dataMatcher.group(0);
save(fieldValue);
}
dataFormat
is editable in application settings by users, barcode
is read by the data scanner.