cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP will suspend normal business operations for our Winter Holiday beginning on Wednesday, Dec. 24, 2025, at 5:00 p.m. ET (2:00 p.m. ET for JMP Accounts Receivable).
    Regular business hours will resume at 9:00 a.m. ET on Friday, Jan. 2, 2026.
  • We’re retiring the File Exchange at the end of this year. The JMP Marketplace is now your destination for add-ins and extensions.

Discussions

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

Use Regex to Replace Spaces In a Table Column

I have a table column that contains a variable quantity of spaces in each cell.  I want to collapse those to a single space.  I presume regex can eliminate those but I've never applied regex outside a column formula.  Is this even the best approach and if so, how do I achieve it?


Slán



SpannerHead
1 ACCEPTED SOLUTION

Accepted Solutions
jthi
Super User

Re: Use Regex to Replace Spaces In a Table Column

Collapse Whitespace() is basically meant for this (you can also use other methods)

Names Default To Here(1);

mystr = "a         b";

res1 = Regex(mystr, " +", " ", GLOBALREPLACE);

res2 = Concat Items(Words(mystr, " "), " ");

res3 = Collapse Whitespace(mystr);

show(res1, res2, res3);

Recode has Collapse Whitespace so you can just use that

jthi_0-1738865998371.png

and it will provide you with a script

// Recode column: Column 6
Local({dt},
	dt = Data Table("Big Class");
	dt << Begin Data Update;
	For Each Row(dt, dt:Column 6[] = Collapse Whitespace(dt:Column 6));
	dt << End Data Update;
);

 

 

-Jarmo

View solution in original post

1 REPLY 1
jthi
Super User

Re: Use Regex to Replace Spaces In a Table Column

Collapse Whitespace() is basically meant for this (you can also use other methods)

Names Default To Here(1);

mystr = "a         b";

res1 = Regex(mystr, " +", " ", GLOBALREPLACE);

res2 = Concat Items(Words(mystr, " "), " ");

res3 = Collapse Whitespace(mystr);

show(res1, res2, res3);

Recode has Collapse Whitespace so you can just use that

jthi_0-1738865998371.png

and it will provide you with a script

// Recode column: Column 6
Local({dt},
	dt = Data Table("Big Class");
	dt << Begin Data Update;
	For Each Row(dt, dt:Column 6[] = Collapse Whitespace(dt:Column 6));
	dt << End Data Update;
);

 

 

-Jarmo

Recommended Articles