- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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
Any advice and help would be much appreciated.
Thank you
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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, ", ");
));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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" )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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, ", ");
));
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Extract failure part code from unstructured string
Thanks Jarmo. This is great!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
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" )
);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Get Direct Link
- Report Inappropriate Content
Re: Extract failure part code from unstructured string
Thanks for sharing this function "New Column by Text Matching". It helps.