cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Don’t miss your chance to experience Discovery Summit Europe at our best available rate! Early bird registration through 31 Oct.
  • Image to Table JMP extension imports single or batch images as data tables. Useful to extract curves from pictures or convert image data to curve data to use in analyses like Functional Data Explorer. Download and install the extension.

Discussions

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

JSL Regular substitution: Replaces the same line | and the following characters with null

Such as

BPS<4.05|is Missing(BPS)
BPS>=2.75
ab>=1961734|is Missing(ab)
efg<13741

to

BPS<4.05
BPS>=2.75
ab>=1961734
efg<13741

Thanks!

3 REPLIES 3
jthi
Super User

Re: JSL Regular substitution: Replaces the same line | and the following characters with null

There isn't a need to use Regexes for this, Words + Word should be enough

Names Default To Here(1);

mystr = "\[BPS<4.05|is Missing(BPS)
BPS>=2.75
ab>=1961734|is Missing(ab)
efg<13741
]\";

mylist = Words(mystr, "\!N");

comparisons = Transform Each({line}, mylist,
	Word(1, line, "|");
);

result = Concat Items(comparisons, "\!N");
-Jarmo
lala
Level IX

Re: JSL Regular substitution: Replaces the same line | and the following characters with null

Thanks!

  • I prefer to use regular.

mystr = "\[BPS<4.05|is Missing(BPS)
BPS>=2.75
ab>=1961734|is Missing(ab)
efg<13741
]\";

t1=Regex(mystr,"\|(.[^)]{0,})\)","",globalreplace);
jthi
Super User

Re: JSL Regular substitution: Replaces the same line | and the following characters with null

It can also be a good option. Sometimes regex patterns are difficult to understand and you can end up with difficult patterns (especially if you have corner cases) but it is very flexible

 

View more...
Names Default To Here(1);

rgx_parse = function({str}, {Default Local},
	// new_str = Regex(str, "\|.+?\)", "", GLOBALREPLACE);
	new_str = Regex(str, "\|(.[^)]{0,})\)", "", GLOBALREPLACE);
	
	return(new_str);
);

words_parse = function({str}, {Default Local},
	mylist = Words(str, "\!N");

	comparisons = Transform Each({line}, mylist,
		Word(1, line, "|");
	);

	result = Concat Items(comparisons, "\!N");
);

mystr1 = "\[BPS<4.05|is Missing(BPS)
BPS>=2.75
ab>=1961734|is Missing(ab)
efg<13741
]\";

mystr2 = "\[BPS<4.05|is Missing(BPS)
BPS>=2.75|
ab>=1961734|is Missing(ab)
efg<13741
]\";

mystr3 = "\[BPS<4.05|is Missing(BPS)
BPS>=2.75|)abc
ab>=1961734|is Missing(ab)
efg<13741
]\";


Show(rgx_parse(mystr1));
Show(words_parse(mystr1));
write("\!N");

Show(rgx_parse(mystr2));
Show(words_parse(mystr2));
write("\!N");

Show(rgx_parse(mystr3));
Show(words_parse(mystr3));
write("\!N");

 

-Jarmo

Recommended Articles