Try this:
Edit: This also works (?<=XYZ|Test) (?=Sans).
(?<=XYZ) (?=Sans)|(?<=Test) (?=Sans)
1- (?<=XYZ) (?=Sans) match a space preceded by XYZ but do not include XYZ as a part of that match, at the same time the space should be followed by Sans, but don't include Sans as a part of the match, we only want the space . This part will match the first space between XYZ Sans
2- | the alternation operator | , it is like Boolean OR If the first part of the regex(i.e., the pattern before |) matches a space , the second part of the regex(i.e., the pattern after |) will be ignored, this is not what we want because of that we have to add g modifier which means get all matches and don't return after first match. See live demo. to check the g modifier and try to unset it and see the result. it is the g right after the regex pattern looks like that /(?<=XYZ) (?=Sans)|(?<=Test) (?=Sans)/g <<
3- (?<=Test) (?=Sans) match a space preceded by Test but do not include Test as a part of that match, at the same time the space should be followed by Sans, but don't include Sans as a part of the match, we only want the space. This part will match the second space between Test Sans
EDIT:
This is another regex pattern will match any space exists inside the value of -font:, it is dynamic.
(?<=-font:\s*['\x22][^'\x22]*?)\s(?=[^'\x22]*)
See live demo.
"data-template='Test xxx' root{--primary-font:'XYZ Sans';--secondary-font:'Test Sans';--hero-background:#ffbe3f;--header-colour-highlight:#f0591e;--header-background:#ffffff;--header-colour-tabs:#1d2130; }"
The C# code that does what you want is something like this:
Note: I updated the regex pattern in the code.
using System;
using System.Text.RegularExpressions;
public class Example
{
public static void Main()
{
string input = "\"data-template='Test xxx' root{--primary-font:'XYZ Sans';--secondary-font:'Test Sans';--hero-background:#ffbe3f;--header-colour-highlight:#f0591e;--header-background:#ffffff;--header-colour-tabs:#1d2130; }\"";
string pattern = @"(?<=-font:\s*['\x22][^'\x22]*?)\s(?=[^'\x22]*)";
string replacement = "";
string result = Regex.Replace(input, pattern, replacement);
Console.WriteLine("Original String: {0}", input);
Console.WriteLine("\n\n-----------------\n\n");
Console.WriteLine("Replacement String: {0}", result);
}
}
-fontvariables, and another to replace the blank spaces in it. Otherwise, this should dosed -E "s/-font:'(\S*)\s+(\S*)';/-font:'\1\2';/g"