InDesign uses Perl-compatible regular expressions (pcre). Getting a Unicode character into the replacement string is done by \x{XXXX} where XXXX is the hexadecimal character code:

2\x{2009}$5

But in general you can replace by any character you can type. Just put actual thin spaces into your search-and-replace dialog:

3 $5

You can use your OS's utilities to grab the thin space from the list of available characters, for Windows it's the "Character Map" tool, where the thin space can be found in the "General Punctuation" Unicode sub-range. Searching for "thin space" works as well. MacOS has the "Character Viewer", which can do the same thing.

Answer from Tomalak on Stack Overflow
Top answer
1 of 2
2

If you're not worried about performance, you can replace all the manual work by using the <regex> facilities, which results in a considerable reduction of code to test and maintain.

#include <regex>

source = std::regex_replace(source, std::regex("€"), "\x80");

I would still keep it in a separate function to make it easy to change the implementation afterwards.

2 of 2
1

You don't need the std::vector<std::uint8_t> objects at all. You can use the input std::string objects directly.

Also, the code in the while loop needs to be updated for the following issues:

  1. Make sure to capture the return value opf source.erase. If you don't the iterator is invalid.

  2. To avoid infinite loop, use itr as the first argument to std::search.

  3. Update itr inside the loop appropriately to avoid an infinite loop.

void replaceAllOccurences(std::string& source,
                          const std::string& replaceFrom,
                          const std::string& replaceTo)
{
   std::string::iterator itr = source.begin();
   while((itr = std::search(itr, source.end(), replaceFrom.begin(), replaceFrom.end())) != source.end())
   {
      itr = source.erase(itr, itr + replaceFrom.size());

      // itr is going be invalid after insert. Keep track of its
      // distance from begin() so we can update itr after insert.
      auto dist = std::distance(source.begin(), itr);

      source.insert(itr, replaceTo.begin(), replaceTo.end());

      // Make itr point to the character 1 past what got replaced.
      // This will avoid infinite loop incase the first character of
      // replaceTo is the same as the character being replaced.
      itr = std::next(source.begin(), dist+1);
   }
}
Discussions

c# - Replace Unicode character "�" with a space - Stack Overflow
I'm a doing an massive uploading of information from a .csv file and I need replace this character non ASCII "�" for a normal space, " ". The character "�" corresp... More on stackoverflow.com
🌐 stackoverflow.com
Regex unicode chars in C++ - Stack Overflow
I have the following part of a configuration file (for example, .ini file) that is corrupted and I am developing a C ++ application that detects file corruption, using regex, detecting invalid char... More on stackoverflow.com
🌐 stackoverflow.com
find and replace unicode by regex
At first pass the thing that comes to mind is to use a hashtable. This might be a little messy but it avoids code repeat if you need to add or remove any key/values. I'm sure someone can come up with a slick method. $Path = 'C:\Temp\Content.txt' $DestFile = 'C:\Temp\DestFile.txt' $HashTable = @{ '¨' = '1' '©' = '2' 'ª' = '3' '«' = '4' '¬' = '5' '°' = '6' } [regex]$Regex = $HashTable.Keys -join '|' $Result = switch -Regex -File $Path { $Regex { $_ -replace $Matches.0, $HashTable[$Matches.0] } default { $_ } } $Result | Out-File $DestFile More on reddit.com
🌐 r/PowerShell
5
4
July 8, 2019
c# - replace unicode character - Stack Overflow
Read this article for a good discussion of this issue. Do yourself a favor and forget RegexOptions.Compiled even exists until you run into a problem you can't solve without it. ... No they aren't.There are space character in @"\\u0 ". ... Also, your replacement string should be either "@\u0" ... More on stackoverflow.com
🌐 stackoverflow.com
January 3, 2013
🌐
Unicode
unicode.org › reports › tr18
UTS #18: Unicode Regular Expressions
Code points that are syntax characters or whitespace are typically escaped. For more information see [UAX31]. In examples, the syntax "\s" is sometimes used to indicate whitespace. See also Annex C: Compatibility Properties. Also, in many regex implementations, the first position after the opening '[' or '[^' is treated specially, with some syntax chars treated as literals.
🌐
Regular-Expressions.info
regular-expressions.info › refunicode.html
Regular Expression Unicode Character and Property Reference
Inside a character class, these tokens add the characters that they normally match to the character class. The word Property in the Syntax column in the table below needs to be substituted with one of the Unicode properties that you can find in the references pages for which categories, scripts, blocks, binary properties, or one value in a property set.
🌐
Reddit
reddit.com › r/powershell › find and replace unicode by regex
r/PowerShell on Reddit: find and replace unicode by regex
July 8, 2019 -

i have several strings of characters that have unicode at the end of them. I would like to do a find with regex and replace the unicode with the specified characters.

30May19Bel©
13Jun18Bel¬
24Aug17Sar«

I would like to do a find and replace with regex

for example [0-9]{2}[a-zA-Z]{3}[0-9]{2}[a-zA-Z]{3}©

$path = 'C:temp\uni.txt'
$original_file = C:temp\uni.txt"
$destination_file = "C:temp\update.txt"
(Get-Content $original_file) | Foreach-Object {
    $_ -replace '¨', '1'`
     -replace '©', '2'`
     -replace 'ª', '3'`
     -replace '«', '4'`
     -replace '¬', '5'`
     -replace '°', '6'`
     
    } | Set-Content $destination_file

and replace it with

30May19Bel2
13Jun18Bel5
24Aug17Sar4

This may be a caveman approach, and I know nothing about regex. If there is a better way, i am unaware of it, but totally open to someone dropping the egg of knowledge on me. It just seemed like the easiest way was to create a Rosetta Stone of sorts. Thanks, Rogue

Find elsewhere
🌐
AutoHotkey
autohotkey.com › board › topic › 97682-how-can-i-specify-unicode-characters-in-regexreplace-replacement-parameter
How can I specify unicode characters in RegExReplace replacement parameter? - Ask for Help - AutoHotkey Community
September 18, 2025 - That aside, regex applies to the needle parameter only; it is not used in the replacement parameter. To get the characters you should be able to enter them in as literal text or call their equivalent using the Chr() function.
🌐
Unicode
unicode-org.github.io › icu › userguide › strings › regexp.html
Regular Expressions | ICU Documentation
ICU’s Regular Expressions package provides applications with the ability to apply regular expression matching to Unicode string data. The regular expression patterns and behavior are based on Perl’s regular expressions. The C++ programming API for using ICU regular expressions is loosely based on the JDK 1.4 package java.util.regex, with some extensions to adapt it for use in a C++ environment.
🌐
Xojo Programming Forum
forum.xojo.com › general
Regex fails if the source string contains the Unicode replacement character - General - Xojo Programming Forum
November 2, 2023 - This regex: Var instr, outstr As ... for me unless the input string (instr) contains the Unicode replacement character (U+FFFD �, UTF-8: ef bf bd). In the case where instr does contain this character, then the regex does ......
🌐
UiPath Community
forum.uipath.com › help › studio
How to replace unicode in string - Studio - UiPath Community Forum
November 25, 2021 - Hi, i’m try to replace unicode in string like : Tổng cộng → Tong cong I’m try to use the way in this topic but result gonna be : T?ng c?ng Any idea for this, please help Thanks
🌐
Microsoft Learn
learn.microsoft.com › en-us › answers › questions › 916103 › replace-unicode-chars-to-non-unicode-in-std-string
Replace UNICODE chars to non-UNICODE in std::string - Microsoft Q&A
I have the following std::string: Mure╚Ö How can I replace the last UNICODE char to non-UNICODE ? I have tried: s = std::regex_replace(s, std::regex("╚Ö"), "a"); but I got: Unhandled exception at 0x75ECC3A2 in…
🌐
Community
community.safe.com › home › forums › fme form › transformers › replace unicode character in kml
Replace Unicode character in KML - FME Community
August 1, 2017 - Try the following regex in a StringReplacer, it will replace any character in a certain unicode range (in the below example it's the range 0800-FFFF) with the replacement text of your choice:
🌐
Stack Exchange
vi.stackexchange.com › questions › 26739 › use-unicode-string-to-replace-cjk-characters
Use unicode string to replace cjk characters - Vi and Vim Stack Exchange
August 5, 2020 - It can replace 你 with you,it turn out to be i and you,i change i and 你 into i and you,now i want to change reversely,change i and you into i and 你,it can be done with %s/you/你/g,try another way: ... That is because \%u4f60 is a regex atom, that is only valid in the search part of the :s. ... The \%u expression is only a valid syntax for the pattern of a search or of a :s, and not for the replacement part. See :help /\%u. Similarly to other search pattern syntax such as \s to match whitespace, * to match repeats of the previous item, etc. In order to produce this character on the replacement side, you have a few options.
🌐
Stack Overflow
stackoverflow.com › questions › 39849114 › regex-js-replace-character-by-unicode
regex js: Replace character by unicode - javascript
October 4, 2016 - It has roots in a piece. of classical Latin literature from 45 BC?</p> ... Well, the code does not seem to work at all. Note that you can also replace with &#8239; entity. .replace(/.\?/g, '&#8239;?') ... I my example, I would like to add narrow no-break space between the C and the ? on the last sentence. ... converts zero or more space or narrow non break space characters in text, followed by '!' or '?', into a single narrow non break space character followed by the '!' or '?' character matched (tested in Firefox and IE).