CosmicAdverb
CosmicAdverb

Reputation: 1

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.

Upvotes: 0

Views: 30

Answers (2)

MonkeyZeus
MonkeyZeus

Reputation: 20737

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
  • Pce$ - end with Pce
  • gms - global, multi line, and single line modifiers

https://regex101.com/r/RXaAT4/1

Upvotes: 1

sp00m
sp00m

Reputation: 48817

. 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$

Upvotes: 1

Related Questions