Hi everyone,
I have a string like below " [CDO600705010] [S 88ABCV A B IT] [C23204348IT] "
Do you know how to get characters between open and close bracket
For instance:
CDO600705010
S 88ABCV A B IT
C23204348IT
Sincerely
s=" [CDO600705010] [S 88ABCV A B IT] [C23204348IT] "; one = word(2,s,"[]"); show(one); /*: one = "CDO600705010";
Amazing! Appreciate It works like miracle
I like @txnelson's approach. I often use it. The character functions are handy!
Here is another approach using Regex() instead. It is not a solution. It is an illustration of how you might parse each string. I show two search patterns, but other patterns are possible. I wonder which way is faster, as it might be a consideration with many strings.
Names Default to Here( 1 ); string = { "[CDO600705010]", "[S 88ABCV A B IT]", "[C23204348IT]" }; n = N Items( string ); For( s = 1, s <= n, s++, Show( Regex( string[s], "([\w\d\s]+)", "\1" ); ); ); For( s = 1, s <= n, s++, Show( Regex( string[s], "[^\-[\]]+" ); ); );
Word() is the function every JMP user should know.
If you learn only one Formula Editor function, Word() is the one
I would definitely go with Word() or Words() with this one, but there is a Character Pattern thingie in JMP. It is fairly difficult to learn and it might have a bit limited use when compared to more simple methods (I haven't bothered to learn it). Script modified from a script found from Re: Extract text from string (post also has explanation of the matching)
Names Default To Here(1); // see https://community.jmp.com/t5/Discussions/Extract-text-from-string/td-p/450420 txt = " [CDO600705010] [S 88ABCV A B IT] [C23204348IT] "; sp = Pat Span("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890 "); found_list = {}; Pat Match( txt, "[" + sp >> match + ("]") + Pat Test( Insert Into(found_list, match); 0; ) ); show(found_list); // found_list = {"CDO600705010", "S 88ABCV A B IT", "C23204348IT"};
But matching between multiple brackets could be one place where I could see myself using Character Patterns.
See also Scripting Guide > Types of Data > Pattern Matching