cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Choose Language Hide Translation Bar
bzanos
Level III

Extract failure part code from unstructured string

Hi,

I want to extract failure part codes from the unstructured string below using Regex in JSL. But I was not success to get it because it is complicated. 

 

Repair T126 & PA21. retest pass
change L6C, FTNG4 reroute for retest
Test 1 failure part P12; M531, Z6A2. Test 2 failure part Z100, RT98; BTGH9. Rework all the parts
failure parts replaced (K3; LG69; AK4T). Proceed to next test
damaged part YT10 rework the part, proceed to next process

 

Required outcome in column "Failure Part Code" should look something this 

bzanos_1-1700203089664.png

 

Any advice and help would be much appreciated.

 

Thank you

 

 

2 ACCEPTED SOLUTIONS

Accepted Solutions
jthi
Super User

Re: Extract failure part code from unstructured string

Capturing multiple things with single regex isn't that simple in JMP as there isn't global matching possibility (

 

This fairly simple regex does capture first codes for you 

Names Default To Here(1);

dt = Open("$DOWNLOADS/data1.jmp");

failure_pattern = "[A-Z]+\d+[A-Z]?";

Eval(EvalExpr(
	dt << New Column("A", Character, Nominal, << Formula(
		Regex(:Repair Details, Expr(failure_pattern));
	));
));

 

And then pattern matching mess (can be most likely made much better)

Names Default To Here(1);

dt = Open("$DOWNLOADS/data1.jmp");

str = "failure parts replaced (K3; LG69; AK4T). Proceed to next test";

dt << New Column("A", Character, Nominal, << Formula(
	failure_pattern = "([A-Z]+\d+[A-Z]?){1,}";
	found_list = {};
	Pat Match(:Repair Details,
		Pat Any(", (") + Pat Regex(failure_pattern) >> match + Pat Any(" .;,)") + Pat Test(
			Insert Into(found_list, match);
			0
		)
	);
	Concat Items(found_list, ", ");
)); 
-Jarmo

View solution in original post

mmarchandTSI
Level V

Re: Extract failure part code from unstructured string

I recently discovered a JMP function/option that can handle this pretty easily.  New Column by Text Matching.

 

Try this script or use the utility under Cols->Utilities with your Repair Details column selected.

 

New Column by Text Matching(
	Column( :Repair Details ),
	Set Regex( Custom( Title( "parts" ), Regex( "([A-Z]+\d+[A-Z]?)" ), Result( "\[\1]\" ), ) ),
	Output Column Name( "Failure Part Code" )
);

 

mmarchandTSI_0-1700228913630.png

 

View solution in original post

4 REPLIES 4
jthi
Super User

Re: Extract failure part code from unstructured string

Capturing multiple things with single regex isn't that simple in JMP as there isn't global matching possibility (

 

This fairly simple regex does capture first codes for you 

Names Default To Here(1);

dt = Open("$DOWNLOADS/data1.jmp");

failure_pattern = "[A-Z]+\d+[A-Z]?";

Eval(EvalExpr(
	dt << New Column("A", Character, Nominal, << Formula(
		Regex(:Repair Details, Expr(failure_pattern));
	));
));

 

And then pattern matching mess (can be most likely made much better)

Names Default To Here(1);

dt = Open("$DOWNLOADS/data1.jmp");

str = "failure parts replaced (K3; LG69; AK4T). Proceed to next test";

dt << New Column("A", Character, Nominal, << Formula(
	failure_pattern = "([A-Z]+\d+[A-Z]?){1,}";
	found_list = {};
	Pat Match(:Repair Details,
		Pat Any(", (") + Pat Regex(failure_pattern) >> match + Pat Any(" .;,)") + Pat Test(
			Insert Into(found_list, match);
			0
		)
	);
	Concat Items(found_list, ", ");
)); 
-Jarmo
bzanos
Level III

Re: Extract failure part code from unstructured string

Thanks Jarmo. This is great!

mmarchandTSI
Level V

Re: Extract failure part code from unstructured string

I recently discovered a JMP function/option that can handle this pretty easily.  New Column by Text Matching.

 

Try this script or use the utility under Cols->Utilities with your Repair Details column selected.

 

New Column by Text Matching(
	Column( :Repair Details ),
	Set Regex( Custom( Title( "parts" ), Regex( "([A-Z]+\d+[A-Z]?)" ), Result( "\[\1]\" ), ) ),
	Output Column Name( "Failure Part Code" )
);

 

mmarchandTSI_0-1700228913630.png

 

bzanos
Level III

Re: Extract failure part code from unstructured string

Thanks for sharing this function "New Column by Text Matching". It helps.