Regular expression for fetching data from excel

Hi all,

Excel file has few data need to extract the data from excel file and need to perform the match operation.
Pattern is:
PT6A-67F
PW545C
PT6A-140AG
PT6T-3BGB
PW207E
PT6C-67E
PW120A
PW545C
PW306D1
PW306C
PW545C
PT6A-42
How to write regular expression to fetch the above data.
Please help.
Thanks,
Lakshmi

Hi @lakshmi.mp

What is the input raw text and what is the required extracted text?

Hey!

Could you please mention the input text and also expected output text?

Regards,
NaNi

Hi,

Input 1

WORKSCOPE 
PZ6A-67F ENGINE 
DELIVERY OF SERVICE 15-Feb-22
CREDIT RELEASE NA
EXCHANGE RATE USED 1.3506

Input 2

TO PERFORM 
PT6J-67F ENGINE 
DELIVERY 
CREDIT RELEASE NA
EXCHANGE 

Input3
CARRY OUT H.S.I. ON PP545C AA
Input 4
LGB - SO 228902 PW545C SSN: DF0408 HOT SECTION INSPECTION
4 input samples
And expected output is- PZ6A-67F
PT6J-67F
PP545C
PW545C
PT6A-67F
PW545C
PT6A-140AG
PT6T-3BGB
PW207E
PT6C-67E
PW120A
PW545C
PW306D1
PW306C
PW545C
PT6A-42
Regards,
Lakshmi

@lakshmi.mp
have a try on this->

Regex.Match(input_String.ToString.Trim,"(\bP[A-Z0-9\-]*)").ToString.Replace("Perform","").tostring

Hi @Vaibhav_Rajpoot_17 ,


Above highlighted with yellow should match but its matching what ever starts with P.
What changes i need to do.
Thanks,
Lakshmi

@lakshmi.mp

as your provided image , you are trying to fetch the model number?

@Vaibhav_Rajpoot_17 ,
yes need to extract the model from column .

@lakshmi.mp

you can use the model name as anchor for fetching the required data.
have a look on this thread->

Regex.Match("model: PT6A-114A","(?<=model)[\:\ ]*[\bP\d\w\-]*").ToString.Replace(":","").Trim

Hi @lakshmi.mp

Try this expresstion

System.Text.Regularexpression.Regex.Match(InputString,"(?<=model\s:\s)\S+").Tostring

Regards
Gokul

Hi,

LGB - SO 228902 PW545C SSN: DF0408 HOT SECTION INSPECTION
How to extract in this case.
And expected output is- PZ6A-67F

Thanks,
Lakshmi

Hey!

Try this:

System.Text.RegularExpressions.Regex.Match(StrVariable,"[P][A-Z]\d{1,}[A-Z].\d+\D|[P][A-Z]\d{1,}[A-Z0-9]{1,}").ToString

Reference:

Regards,
NaNi

Hi @THIRU_NANI ,
Tried with the expression .
image
How to match highlighted with yellow, tried by placing “*” not able to match. What changes I need to do.

Thanks,
Lakshmi

Hey!

How about this

Regards,
NaNi

Hi @THIRU_NANI ,

This expression matches only few of the patterns & in another

matches all but not able to match
image
This pattern. What changes i need to do.

Regards,
Lakshmi

Hey!

Just you have to use 2 expressions in one single regex separator(|)…

Try this:

System.Text.RegularExpressions.RegEx.Match("strInput","[P]\D\d\D-\d{1,}[A-Z]{1,}|[P][A-Z]\d{1,}[A-Z].\d+\D|[P][A-Z]\d{1,}[A-Z0-9]{1,}").ToString

Reference:

Regards,
NaNi

1 Like

@THIRU_NANI , Thanks a lot for helping and providing solution. Its working now.

Thanks & Regards,
Lakshmi

1 Like

Hey!

Could you please create a new thread and provide the input and expected output…

Regards,
NaNi

1 Like

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