Extracting characters within certian pattern including square bracketsHi,
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.
Automation and ScriptingBasic Data Analysis and ModelingRe: Extracting characters within certian pattern including square bracketsYou 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"));
</CODE></P>
<P> </P></LINGO-BODY><LINGO-SUB id="lingo-sub-827635" slang="en-US" mode="CREATE">Re: Extracting characters within certian pattern including square brackets</LINGO-SUB><LINGO-BODY id="lingo-body-827635" slang="en-US" mode="CREATE"><P>Also using Word(-1,...) might be enough if your strings are simple enough</P>
<PRE><CODE class=" language-jsl">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";
Re: Extracting characters within certian pattern including square bracketsThank you. This works perfect. Could you please explain why "$" is in the code?
Re: Extracting characters within certian pattern including square bracketsMost likely unnecessary, but it just tries to make sure it matches at the end
Re: Extracting characters within certian pattern including square bracketsYou 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, "[]"));