I have a regex that detects something called a PO Number that is PO Number followed by some characters that may or may not be digits but certainly contains a digit. It can also have spaces.
You can see the link to find the problem.
Pattern:
((P\s*o\s*(\#|Number|No|\.)*\s*([:=\-\'\s\.])?\s*(\d*\s?([A-Z\-\/]*\s?\d+)+[A-Z\-]*)))
The problem arises when there is something like:
Case 3. Ship on 123
Here p is followed by o and the following conditions are good for match. But I needed to check the condition preceding 'p' that is 'shi'p.
Clearly, I needed to implement something to avoid p preceded by a plain word [A-Z]+ but allow p if its preceded by a space or a digit. Following conditions should pass.
Case 1. YO#11111PO#2015 S53-55A
Case 2. YO#12345_PO#234 S34-34A
I tried using word boundary \b but that causes case 1 and 2 to fail. Is there another way.
Try preceding your regexp with (?:[^a-z])
This is a non-capturing group so when you interpret your groups it won't appear in the list.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With