search substring from vareity of stringI have a column with name of failure, which contains all variety of strings. I like to search error code with start of "ex". the error code is 10-character string with start of "ex". and put the 1st error code into column of "1st code", all error codes into column of "all codes. what formula is set to both columns? sorry to bother again. I need to quickly make my work in hands closed firstly, then take time to learn JMP help document.

Basic Data Analysis and ModelingRe: search substring from vareity of stringThis post might help Extract failure part code from unstructured string
Re: search substring from vareity of stringHere is one way to create these 2 columns
Formula for :fst code
start = contains(:Failure,"0x");
if(start>0,substr(:Failure,start,start+10),"");
Formula for :All Codes
theCodes = {};;
theString = :Failure;
While( Contains( theString, "0x" ) > 0,
start = Contains( theString, "0x" );
Insert Into( theCodes, Substr( theString, start, start + 10 ) );
theString = Substr( theString, start + 10 );
);
concat items(theCodes, ",");Re: search substring from vareity of stringReally appreciate your timely assistance. with the formula, error codes are picked up but some other characters show up as well. I solved it using left(). but I like to know why the other characters show up over there?

Re: search substring from vareity of stringWithout having your data table to use to debug the issue, I am not sure what the issue is. Try this modification and see if it works better.
start = contains(:Failure,"0x");
x="";
if(start>0,x=substr(:Failure,start,start+10),"");
x;
Re: search substring from vareity of string@txnelson thanks for your time on the topic. I tried it again, it still fails. here is the data table for your debug.
Re: search substring from vareity of stringMy error,
The length of the Substr element should be Start, not Start+10.
First Code
start = Contains( :Failure, "0x" );
If( start > 0,
Substr( :Failure, start, 10 ),
""
);
All Codes
theCodes = {};
theString = :Failure;
While( Contains( theString, "0x" ) > 0,
start = Contains( theString, "0x" );
Insert Into( theCodes, Substr( theString, start, 10 ) );
theString = Substr( theString, start + 10 );
);
Concat Items( theCodes, "," );Re: search substring from vareity of stringthanks a million!
Re: search substring from vareity of stringIf it is possible that you have messages mixed in which start with 0x but aren't error codes simple Contains might work, but based on the examples you have provided us with, this doesn't seem to be the case (or if you have for example 0x123456 which is shorter than what you defined as errorcode).
If this ends up being the case, I would look at the Regex (you can use similar idea with While loop as Jim did show with contains). But you have to have good knowledge of the allowed characters to build robust pattern for proper matching.
Re: search substring from vareity of string@jthi thanks for your comments. I am trying to use Regex to search the substring starting with 0x. based on your recommended post, it's a good idea for "New Column by Text Matching". I am thinking how to build the pattern for the error code ( or the error code is not limited to 10 characters). the instruction of Backreferences and Capturing Groups for Regex can help me to understand the related JSL, but it's a little hard for me to write JSL. i think more JSL examples I read, sooner I learn to write JSL. back to the subject, could you do me a favor to show the Regex pattern of the error code? for example in your post, it is
failure_pattern = "[A-Z]+\d+[A-Z]?"
Re: search substring from vareity of stringGiven the sample data table you provided, the formula to pull out the 1st error code using the Regex() function is
Regex( :Failure, "[A-Z]+\d+[A-Z]?" )
The Definition and Examples of the Regex() function is found in the Scripting Index
Re: search substring from vareity of stringJSL might not have all the flags (Regex: add options for all flags ,Add flag to Regex Match() to find all non-overlapping occurances of pattern ) but it does still accept similar patterns. Use something like https://regex101.com/ to test your regex patterns (if you are not sure if they will send data to some server, do not use real data unless you can share it) and then try it in JSL. Websites like regex101 explain the pattern to you.
I don't have proper definition on your error codes so I cannot provide good patterns to start with. I only know it starts with 0x but I would need to know allowed characters, is there any order for these allowed characters and how to determine when it ends (and length if there is one).
Re: search substring from vareity of stringtoday I took some time to read the Definition and Examples of the Regex() function is found in the Scripting Index, and learned Regex pattern structure like ([a-zA-Z])\s([0-9]). it's wonderful sharing that using https://regex101.com/ tests the regex patterns.
Regex() or Regex match() is a little complicated function. I need to find more examples from the community to practice the usage of Regex(). thank you very much for your sharing of the links.