'How to write RegEx for the Below Expression
12345678912345678T / 14750,47932 SS
Vis à 6PC 45H Din 913 M 8x20
Art. client: 294519
QTE: 200 Pce
I want to write a RegEx which can find above stated multiline string type from a long txt file where Starting condition will be "18 digit long word" comprises with numbers and Uppercase alphabets and Ending condition shoould be "Pce"
I have written this much and it only reads first line but don't know what to write next
^[0-9A-Z]{18,18}.*
Any type of help will be appreciated.
Solution 1:[1]
. in most engines doesn't include new lines, hence your match stopping at the end of the line. You could either use the DOTALL flag if available, otherwise hack around with an "include-all" class, for example [\s\S] (a char that is either a space or not a space).
With a lazy quantifier, you could use for example:
^[0-9A-Z]{18}[\s\S]*?Pce$
Solution 2:[2]
You didn't specify a programming language so something like this would work:
/^[\dA-Z]{18}[^\dA-Za-z].*?Pce$/gms
^[\dA-Z]{18}- start with 18 digits and/or capital letters[^\dA-Za-z]- not a digit nor letter.*?- anything, lazily- substitute with
[\s\S]*?if single line modifier is not available to you
- substitute with
Pce$- end withPcegms- global, multi line, and single line modifiers
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | sp00m |
| Solution 2 |
