General regex pattern

EGIN Number: PALLET_M_LIs
ASN Number:AAK 45678 W123456
Electronic Goods In Note Load Reference Number:PK 456789 W2356899

Date / Time / Period
Document/Message Date/Time:2006-11-15T18:07 Booking Date/Time: 2006-11-15T19:00
Arrival Date/Time:2006-11-15T21:00 Departure Date/Time: 2006-11-15T21:30
Free Text
Goods Description: 1 PALLETS RECEIVED DAMAGED 1234561 PALLETS RECEIVED DAMAGED 123456
Non-acceptance Information:1 PALLETS RECEIVED DAMAGED 1234561 PALLETS RECEIVED DAMAGED 123456
Details of Transport
Haulier Number:ABCD5678901234567
Haulier’s Name:CARRIERS NAME456789 Wkjhutuytyut
Name and Address Message
Tesco Receiving Centre Number: AP3456789 Wduiyiu
Depot Number:CLP456789 WzkjdhusWE
Name & Address Description:DEPOT NAME Wdkwadyuw786X
Location Identification
Place/Port of Loading:AA3456789012345678901234xPlace of Transhipment:CC3456789012345678901234x
Place/Port of Discharge: BB3456789012345678901234x Bording Crossing Place:DD3456789012345678901234x

As the above text the *italics *texts are field name and bold text are their respective values
i need to create a general regex pattern to be used in for each loop when each time i enter the
field name i want the respective data. But in the above text two field are in the same line when i enter one field name it extract the whole line including other field also.
I need help to create a pattern.

Hello you can give below a try:

Departure Date\/Time:(.{2,500}?\s)

Just change the field name according to the need

regex reference

Hi,

Can you try the following sample?

System.Text.RegularExpressions.Regex.Match(strData,"(?<="+retString+"\s*).+?(?= |"+lookAhead+")").Value

Sample20220714-3.zip (4.6 KB)

Regards,

1 Like

can you use this file as input
New Text Document.txt (1.0 KB)
when i run your code with this text file as input i get empty spaces as output for some field.
But thanks for your code…

Hi,

How about the following?

System.Text.RegularExpressions.Regex.Match(strData,"(?<="+retString+"\s*).+?(?=\s|"+lookAhead+"|$)"  ).Value

Sample20220714-3v2.zip (3.8 KB)

Thank you @Yoichi it works :innocent:

1 Like

@Yoichi I have an issue in JSON part
while i converting the (.xlsx) file to json ,in the output it has the" \n" in the end of each field value,I don’t know how to remove that one


and also if you look ath date time area you can there is a empty space and colon (" :")is there ,I need to remove that one also.
Can you please help me!!!
stext.txt (1.4 KB)
from this above text file i extract the data and store in that .xlsx file

HI,

Can you try to use Trim method when creating JSON.

strValue = strValue.Trim({" "c,":"c,chr(10),chr(13)})

Regards,

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.