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.
  • Graph Builder Toolbar streamlines interactive graphing. Creates shortcuts on Report and GraphBuilder Helpers toolbars. Download and install the extension.
  • JMP will suspend normal business operations for our Rest and Recharge Day on Friday, October 2, 2026.
    Regular business hours will resume on Monday, October 5, 2026.

Discussions

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

Replace ALL occurrences of a match in a string

Let's say I have a very long string, which essentially are just field names, comma separated. 

My problem, when trying to break it into separate fields, is that some names have comma inside them, like "{0,0}" or "{45,-45}" or "{90,90}".

In order to separate this long string into fields I need to replace that comma with something.

This is a small piece of that string: "Normal_0_{0,0}, Normal_90_{45,-45}" - so I need to replace only that comma that inside curly brackets.

So I wrote this:

matches = Regex (longLine, "(\{\d{1,2})(,)(-?\d{1,2}\})", "\1|\3");

It's supposed to replace all the commas inside the string. But in reality it only replaces the first comma in the string.

Why? And how can I replace ALL the matches?

 

Side question: In this code 

Word(1, "Normal_0_{0,0}, Normal_90_{45,-45}" ,  ", ")

it would split the string by EITHER "," OR " ". How can I split by COMBINATION of characters, specifically split by ", " - comma followed by space?

1 ACCEPTED SOLUTION

Accepted Solutions
miguello
Level VII

Re: Replace ALL occurrences of a match in a string

As usual, few minutes after posting I bumped into the answer in the documentation.

All I needed was GLOBALREPLACE:

matches = Regex (longLine, "(\{\d{1,2})(,)(-?\d{1,2}\})", "\1|\3", GLOBALREPLACE);

View solution in original post

2 REPLIES 2
miguello
Level VII

Re: Replace ALL occurrences of a match in a string

As usual, few minutes after posting I bumped into the answer in the documentation.

All I needed was GLOBALREPLACE:

matches = Regex (longLine, "(\{\d{1,2})(,)(-?\d{1,2}\})", "\1|\3", GLOBALREPLACE);
jthi
Super User

Re: Replace ALL occurrences of a match in a string

For your side question: You cannot easily split with many characters by using Word(s). You might be able to use Regex Match OR you could first replace all ", " (Substitute, Regex) with some special character and then split on that using Word(s).

-Jarmo

Recommended Articles