You don't need regular expressions. Python has a built-in string method that does what you need:

mystring.replace(" ", "_")
Answer from rogeriopvl on Stack Overflow
🌐
Stack Abuse
stackabuse.com › bytes › replace-underscores-with-spaces-in-python
Replace Underscores with Spaces in Python
July 1, 2022 - Regardless of where you see this, you may need to convert these underscores to spaces in your code. We'll see how to do that here. The simplest way to achieve this is to use the string's replace(substr, new_str) method, which takes a substring as an argument, as well as the new string to replace ...
Discussions

How to replace space with underscores using a regex in EPLAN?
Simple character-by-character replacements generally don't need regex, but it can be used. Just replace " " with "_". https://regex101.com/r/kVg9Jn/1 More on reddit.com
🌐 r/regex
9
1
August 26, 2024
How to replace space(s) in a string by another charater like and underscore (_)? - Statalist
I did consider using PyCharm or ... of python and I still might do that. In short as of now this workflow works for me and I usually only update it when I have the spare time as it feeds a side project separate from my PhD research. ... With an appropriate choice of output format as the second argument to the string() function, the need to replace slashes with underscores is ... More on statalist.org
🌐 statalist.org
April 9, 2020
Expression Structure Script to Replace Spaces with Underscore
I have the following transform script but it's only replacing spaces with underscores at the top level of the object structure and not any of the sub-levels. def transform(self, value, quality, timestamp): # Create a new dictionary to store the transformed keys transformed_value = {} # Define ... More on forum.inductiveautomation.com
🌐 forum.inductiveautomation.com
8
0
September 16, 2024
Replace any space ' ' by '_' in 2-charac - C++ Forum
I'm stuck on a problem in Zybooks, the goal is to take a 2-character string input and replace any white space with an underscore. More on cplusplus.com
🌐 cplusplus.com
🌐
ItSolutionstuff
itsolutionstuff.com › post › how-to-replace-underscore-with-space-in-pythonexample.html
How to Replace Underscore with Space in Python? - ItSolutionstuff.com
October 30, 2023 - # Declare String Variable myString = "Hello_This_is_ItSolutionStuff.com_This_is_awesome." # Python string replace underscore with space myString = myString.replace("_", " ") print(myString)
🌐
Reddit
reddit.com › r/regex › how to replace space with underscores using a regex in eplan?
r/regex on Reddit: How to replace space with underscores using a regex in EPLAN?
August 26, 2024 -

Hey, guys. I’m a total newbie when it comes to regex and have no idea what I’m looking at, so I’m asking for your help. How can I replace spaces with underscores using a regex in EPLAN?

Example string: "This is a test" --> "This_is_a _test"

I also have an image of something else I’ve done where I removed '&E5/' from the string so that only "011" was left.

In EPLAN:

Where there are a Source Text and Output Text, one can put RegEx expressions.

Solution:

🌐
w3resource
w3resource.com › python-exercises › re › python-re-exercise-23.php
Python: Replace whitespaces with an underscore and vice versa - w3resource
Write a Python program to replace whitespaces with an underscore and vice versa. ... import re text = 'Python Exercises' text =text.replace (" ", "_") print(text) text =text.replace ("_", " ") print(text) ... Write a Python program to replace all spaces in a string with underscores and then convert underscores back to spaces.
🌐
TutorialsPoint
tutorialspoint.com › article › python-program-to-replace-the-spaces-of-a-string-with-a-specific-character
Python Program to Replace the Spaces of a String with a Specific Character
Original: Hello World Python Modified: Hello-World-Python · Similarly, spaces can be replaced with underscores by passing '_' as the replacement character ? sentence = "This is a Python tutorial" modified_sentence = sentence.replace(' ', '_') ...
Find elsewhere
🌐
ItSolutionstuff
itsolutionstuff.com › post › python-string-replace-tab-with-space-exampleexample.html
Python String Replace Tab with Space Example - ItSolutionstuff.com
October 30, 2023 - myString = 'It\tSolution\tStuff\tcom' # python string replace tab with space newString = myString.replace('\t', ' ') print(newString) Output: Read Also: How to Replace Underscore with Space in Python? It Solution Stuff com · I hope it can help you... Tags: Python ·
🌐
W3Schools
w3schools.com › mysql › mysql_not.asp
MySQL NOT Operator
Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, Python, PHP, Bootstrap, Java, XML and more.
🌐
GitHub
gist.github.com › kranthilakum › 7536042
Python script to replace underscores with spaces · GitHub
Python script to replace underscores with spaces. GitHub Gist: instantly share code, notes, and snippets.
🌐
Statalist
statalist.org › forums › forum › general-stata-discussion › general › 1545744-how-to-replace-space-s-in-a-string-by-another-charater-like-and-underscore-_
How to replace space(s) in a string by another charater like and underscore (_)? - Statalist
April 9, 2020 - So, my question is: what code would replace space(s) in a string by another character like an underscore (_)? ... Four arguments are needed for that function, not three. ... subinstr(s1,s2,s3,n) Description: s1, where the first n occurrences in s1 of s2 have been replaced with s3 subinstr() is intended for use with only plain ASCII characters and for use by programmers who want to perform byte-based substitution.
🌐
JMP User Community
community.jmp.com › t5 › Discussions › Substituting-a-space-for-underscore-in-a-character-string › td-p › 597222
Solved: Substituting a space for underscore in a character string - JMP User Community
June 8, 2023 - Hi, notice that Jarmo's code replaces the underscores with a space character, " ", while your code replaced the underscores with the empty string, "", which was at least part of the problem.
🌐
Python Guides
pythonguides.com › replace-whitespaces-with-underscore-in-python
Python Replace Whitespaces With Underscore
August 25, 2025 - Another Pythonic way is to use the map() function with a small lambda expression. This is not the most common approach, but it’s a neat trick that I’ve used when working with functional-style code. ... # Example: Replace spaces with underscores using map() text = "Boston Housing Price Index" result = "".join(map(lambda x: "_" if x == " " else x, text)) print("Original:", text) print("Modified:", result)
🌐
Wikipedia
en.wikipedia.org › wiki › C_(programming_language)
C (programming language) - Wikipedia
November 10, 2001 - Most of the recently reserved words begin with an underscore followed by a capital letter, because identifiers of that form were previously reserved by the C standard for use only by implementations. Since existing program source code should not have been using these identifiers, it would not ...
🌐
Inductive Automation
forum.inductiveautomation.com › ignition
Expression Structure Script to Replace Spaces with Underscore - Ignition - Inductive Automation Forum
September 16, 2024 - I have the following transform script but it's only replacing spaces with underscores at the top level of the object structure and not any of the sub-levels. def transform(self, value, quality, timestamp): # Create a new dictionary to store the transformed keys transformed_value = {} # Define a helper function to recursively transform the keys def transform_keys(dictionary): # Iterate through each key-value pair in the dictionary for key, val in dictionary.items...
🌐
ItSolutionstuff
itsolutionstuff.com › post › python-replace-dot-with-space-exampleexample.html
Python Replace Dot with Space Example - ItSolutionstuff.com
October 30, 2023 - myString = 'It.Solution.Stuff.com' # python string replace dot with space newString = myString.replace('.', ' ') print(newString)
🌐
Cplusplus
cplusplus.com › forum › general › 269651
Replace any space ' ' by '_' in 2-charac - C++ Forum
In this topic using std::replace_if would be the way to go. ... I think you may be battling against the stream and modern programming style, @fewdiefie. If you are iterating through an entire array then a range-based loop is simpler, safer and possibly open to multi-processor or multi-thread optimisation. If you compare with python, there the standard loop is a range-based loop ("for x in A:").
🌐
Medium
medium.com › @bugsanalyze › how-to-replace-whitespaces-with-underscore-without-using-replace-function-in-python-3b7de422add6
How to replace whitespaces in A String with underscore without using replace function in python? | by G vamsi venkatesh | Medium
August 9, 2022 - In this blog we will be discussing ... . I have a string as below. ... If found empty space at particular index replace the character by dividing into substrings and appending underscore ....
🌐
CL Coding
clcoding.com › 2025 › 02 › write-function-that-replaces-all-spaces.html
Write a function that replaces all spaces in a string with underscores (_). ~ Computer Languages (clcoding)
February 27, 2025 - print(replace_spaces("Python is ... replace_spaces that takes a string s as input. Replace spaces using .replace() s.replace(" ", "_") → Finds all spaces " " in the string and replaces them with underscores "_...
🌐
W3Schools
w3schools.com › js › js_regexp.asp
W3Schools.com
Metacharacters are characters with a special meaning. They can be used to match digits, words, spaces, and more. ... The \d metacharacter matches digits. ... The \w metacharacter matches word characters. A word character is a character a-z, A-Z, 0-9, including _ (underscore).