cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMP® Marketplace
Choose Language Hide Translation Bar
lala
Level VIII

Can Substitute implement the function of regular substitution?

For example, replace the column name [20231216] to show that this 20231216 is a variable 8-digit number:
 
 
Col1[20231216]、Col2[20231219]
For( i = 2, i <= N Col( dt ), i++,
	ca = Column( i ) << Get Name;
	cc = Substitute( ca, "[(.{8,})]", "" );//??
	Column( dt, i ) << set name( cc );
);

Thanks!

1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Can Substitute implement the function of regular substitution?

Below are few different options what you could do (if the case is always like those examples, I would most likely use Word)

Names Default To Here(1);

my_str ="Col2[20231219]";

str1 = Word(1, my_str, "[");
str2 = Regex(my_str, "\[^(.+)\[]\", "\1");
str3 = Left(my_str, 4);
str4 = Substr(my_str, 1, Contains(my_str, "[") - 1);

Show(str1, str2, str3, str4);
-Jarmo

View solution in original post

3 REPLIES 3
jthi
Super User

Re: Can Substitute implement the function of regular substitution?

If you want to just remove [] from your string you can provide multiple values for Substitute for example in a list

 

Names Default To Here(1);

my_str = "[20231216]";
my_new_str = Substitute(my_str, {"[", "]"}, ""); //"20231216"

or you could use regex with something like this

Regex(my_str, "\[\[(.*)\]]\", "\1"); // "20231216"

 

Edit:

Regex can also be used to replacements if needed

Regex(my_str, "\[\[|\]]\", "", GLOBALREPLACE); // "20231216"
-Jarmo
lala
Level VIII

Re: Can Substitute implement the function of regular substitution?

  • I need to get rid of the eight numbers.

Thanks!

 

Col1[20231216] → Col1
Col2[20231219] → Col2
jthi
Super User

Re: Can Substitute implement the function of regular substitution?

Below are few different options what you could do (if the case is always like those examples, I would most likely use Word)

Names Default To Here(1);

my_str ="Col2[20231219]";

str1 = Word(1, my_str, "[");
str2 = Regex(my_str, "\[^(.+)\[]\", "\1");
str3 = Left(my_str, 4);
str4 = Substr(my_str, 1, Contains(my_str, "[") - 1);

Show(str1, str2, str3, str4);
-Jarmo