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
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