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 OverflowYou don't need regular expressions. Python has a built-in string method that does what you need:
mystring.replace(" ", "_")
Replacing spaces is fine, but I might suggest going a little further to handle other URL-hostile characters like question marks, apostrophes, exclamation points, etc.
Also note that the general consensus among SEO experts is that dashes are preferred to underscores in URLs.
import re
def urlify(s):
# Remove all non-word characters (everything except numbers and letters)
s = re.sub(r"[^\w\s]", '', s)
# Replace all runs of whitespace with a single dash
s = re.sub(r"\s+", '-', s)
return s
# Prints: I-cant-get-no-satisfaction"
print(urlify("I can't get no satisfaction!"))
How to replace space with underscores using a regex in EPLAN?
How to replace space(s) in a string by another charater like and underscore (_)? - Statalist
Expression Structure Script to Replace Spaces with Underscore
Replace any space ' ' by '_' in 2-charac - C++ Forum
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: