The purpose of this exercise is to detect fragments of the given text that meet the requirements.
Our primary tool will be regex101.com. Let’s take a moment to get to know its interface:
The key elements of the tool are two windows. The smaller one is used to enter a regular expression. In the larger one you type the text you are analyzing.
On the right are the Explanation and Match Information panels. The first one tries to interpret our expression and the second one displays the identified elements.
Quick reference is knowledge base about regular expressions.
First challenge
Text to analyze:
“Thank you for paying the invoices INVOICE-2023123 and INVOICE-2021133, and we would also like to remind you to pay the invoices INVOICE-202023555 and INVOICE-20201455. We would also like to inform you that we are processing your credit note CR-202345345. We look forward to a successful cooperation in 2023.”
3.Match all digits. In this case I use “\d” which means “digit”. We need "" as escape character. This way the tool knows that we do not mean the letter “d”.
Hello @BrianJ , thank You for submission. All your answers are right. For last exercise
I decided to be a little more careful and avoid matching letter prefix shorter but 2, but results are the same.
Thanks! I’m really gaining an appreciation for the art and science of regex through these workouts.
It’s not just about getting the specific answer to the problem provided correct, but thinking about what else COULD go wrong with the data and proactively coming up with constructs that will successfully handle it.