cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • Sign-in to the JMP Community will be unavailable intermittently Dec. 6-7 due to a system update. Thank you for your understanding!
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.
  • JMP 19 is here! Learn more about the new features.

Discussions

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

Can implement this substitution with an operation with a regex?

For example, this file is a txt file.TAB spacing:
Column 2 contains, column 2 contains
The maximum number of rows is 5
Can you use regular substitution to replace rows with less than 5 such symbols to complete the cell with a total of 5 similar symbols?
Make up as shown in the figure.

2024-10-15_12-01-34.png

Thanks Experts!

13 REPLIES 13
jthi
Super User

Re: Can implement this substitution with an operation with a regular?

Names Default To Here(1);

str = "\[A	B	C
00001	744811604804487748	1
00002	744811604411447740~744811607410407768	1▲1
00003	744811607000017746~744811607407400440~744811607611467718~744811600601460016	1▲1▲1▲1
00004	744811606810447747	1
00005	744811606400167710~744811606610607767~744811608807400040~744811401407170047	1▲1▲1▲1
00006	744811607006017776~744811606014617747~744811600606400074	1▲1▲1
00007	744811607114067714~744811607406147747~744811607704147760~744811607710174146~744811600014600011	1▲1▲1▲1▲1
00008	744811604810187746~744811606706407717~744811606607400107	1▲1▲1
00009	744811608814480014~744811608704464148~744811401101140018~744811401607480040~744811401714140017	1▲1▲1▲1▲1
00010	744811606607177767~744811606707470064~744811608610440011~711741608004176007~744811401606180041~744811401704470014	1▲1▲1▲1▲1▲1
00011	744811607401167716~744811607408417748~711047607710460644~744811607711077714	1▲1▲1▲1
00012	460144607710400044~744811607711077716~744811400601440046~744811401104410044	1▲1▲1▲1
00013	744811607814617747~410144608807046447~744811608110140017~744811400807170010	1▲1▲1▲1
00014	744811607807117717~744811607806117747~744811608610400060~744811608804087740~744811400806070014	1▲1▲1▲1▲1
]\";

lines = Words(str, "\!N");
header = Remove From(lines, 1); // skip header

maxchar = 5;
res = Transform Each({line}, lines,
	row = Words(line, "\!t");
	char_to_add = maxchar - (Length(row[2]) - Length(Substitute(row[2], "~", "")));
	
	item1 = row[1];
	item2 = row[2] || Repeat("~", char_to_add);
	item3 = row[3] || Repeat("▲", char_to_add);
	
	new_line = Eval Insert("^item1^\!t^item2^\!t^item3^");	
);

Insert Into(res, header, 1);

dt = Open(Char to blob(Concat items(res, "\!N")), "text");

jthi_0-1729242162433.png

Scripting Index and Scripting Guide should cover everything you need to do something like this (outside of the last line).

-Jarmo
lala
Level IX

Re: Can implement this substitution with an operation with a regular?

Thanks Experts!

 

python's

        for i in range(4, len(columns)):
            col = columns[i]
jthi
Super User

Re: Can implement this substitution with an operation with a regular?

Use For Each() and Index() in JSL

 

Edit:

Or just use normal For loop, just start loop from 4 and make it non-exclusive to lenght

-Jarmo
lala
Level IX

Re: Can implement this substitution with an operation with a regular?

Thanks Experts!
Transposed is equivalent.

Recommended Articles