I'm trying the text on the long text . exemple : the long text is :
- 02.04.2021 09:23:25 CET #PRS~ #PRS~ ( #UID~ ) Tél. #TEL~ #TEL~ NonConformity 0001 : Type of nonconformity : Scratch
- NonConformity 0002 : Type of nonconformity : Scratch - cosmetical item
- Il a été constaté des rayures sur L'ENS CASQUETTE réf : D54.
- Voir standard doc.
- Nous demandons le renvoi de la pièce pour une remise en conformité.
02.04.2021 09:31:27 CET #PRS~ #PRS~ ( #UID~ ) Tél. #TEL~ #TEL~
Task Completed : 0100 DEC0
Decision Taken : REJECT
Justification :
and I would like only with code Psyspark:
- NonConformity 0002 : Type of nonconformity : Scratch - cosmetical item
- Il a été constaté des rayures sur L'ENS CASQUETTE réf : D5452134500000.
- Voir standard doc.
- Nous demandons le renvoi de la pièce pour une remise en conformité.
I try with :
.withColumn("texte", F.regexp_extract(F.col("description_long_text"), r'([*]\s\D.+(\s*\w*\W*)+)', 0))
I have a good start, but i would also to extract before --, only
Thank you
You can match all following lines that do not start with
--using a negative lookahead(?!--)The pattern matches:
^Start of string[*]\sMatch*and a whitespace character (which could possibly also match a newline)(?!\d|--)negative lookahead, assert not a digit or--directly to the right of the current position.+Match any character except a newline 1 or more times(?:\n(?!--).*)*Optionally repeat matching a newline, assert not--directly after it and then match any character 0 or more times (change to.+for 1 or more times)See a regex demo.
Or with 2 capture groups:
See another regex demo.