cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Learn how to build custom Python data connectors and further customize JMP’s Data Connector Framework with the Python Data Connector Demo, available now in the JMP Marketplace!
  • See how to create experiments to support product design and ID useful product features. Register for June 12 webinar, 2pm US Eastern Time.

Discussions

Solve problems, and share tips and tricks with other JMP users.
Choose Language Hide Translation Bar
eugur
Level I

Extracting characters within certian pattern including square brackets

Hi,
I have want to extract information from a text in a table row that includes square brackets.
Example Rows in text column:
Plate[QWE147] Reg[ABC123]
Plate[ASD258] Reg[DEF456]

 

Information I want to extract:
ABC123

DEF456

 

What is the best way to do this? I wanted to do it with regex but square brackets makes it complicated.

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Extracting characters within certian pattern including square brackets

You have to do some escaping

Names Default To Here(1);

str1 = "Plate[QWE147] Reg[ABC123]";
str2 = "Plate[ASD258] Reg[DEF456]";

Show(Regex(str1, "Reg\!\[(.+)]$", "\1"));
Show(Regex(str2, "Reg\!\[(.+)]$", "\1"));

 

-Jarmo

View solution in original post

5 REPLIES 5
jthi
Super User

Re: Extracting characters within certian pattern including square brackets

You have to do some escaping

Names Default To Here(1);

str1 = "Plate[QWE147] Reg[ABC123]";
str2 = "Plate[ASD258] Reg[DEF456]";

Show(Regex(str1, "Reg\!\[(.+)]$", "\1"));
Show(Regex(str2, "Reg\!\[(.+)]$", "\1"));

 

-Jarmo
jthi
Super User

Re: Extracting characters within certian pattern including square brackets

Also using Word(-1,...) might be enough if your strings are simple enough

Names Default To Here(1);

str1 = "Plate[QWE147] Reg[ABC123]";
str2 = "Plate[ASD258] Reg[DEF456]";

Show(Word(-1, str1, "[]")); // Word(-1, str1, "[]") = "ABC123";
Show(Word(-1, str2, "[]")); // Word(-1, str2, "[]") = "DEF456";
-Jarmo
eugur
Level I

Re: Extracting characters within certian pattern including square brackets

Thank you. This works perfect. Could you please explain why "$" is in the code?

jthi
Super User

Re: Extracting characters within certian pattern including square brackets

Most likely unnecessary, but it just tries to make sure it matches at the end

-Jarmo
pmroz
Super User

Re: Extracting characters within certian pattern including square brackets

You can also use the word function:

Names Default To Here(1);
str1 = "Plate[QWE147] Reg[ABC123]";
str2 = "Plate[ASD258] Reg[DEF456]";
show(word(4, str1, "[]"));
show(word(4, str2, "[]"));

Recommended Articles