cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • New to JMP? Join us Sept. 23-24 for the Early User Edition of Discovery Summit, tailor-made for new users. Register now for free!
  • Your voice matters! Tell us how you prefer to receive JMP updates, so we can tailor our communication to your needs. Take short survey.
  • See how to access JMP Marketplace - and - find, create & share add-ins to extend your JMP. Watch video.

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