Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

string without space pythonm

import re

string = '  Hello  World   From Pankaj 	

	Hi There  '

print('Remove all spaces using RegEx:
', re.sub(r"s+", "", string), sep='')  # s matches all white spaces
print()

print('Remove leading spaces using RegEx:
', re.sub(r"^s+", "", string), sep='')  # ^ matches start
print()

print('Remove trailing spaces using RegEx:
', re.sub(r"s+$", "", string), sep='')  # $ matches end
print()

print('Remove leading and trailing spaces using RegEx:
', re.sub(r"^s+|s+$", "", string), sep='')  # | for OR condition
Comment

PREVIOUS NEXT
Code Example
Python :: csv reader url 
Python :: fluffy ancake recipe 
Python :: sns histplot change legend labels 
Python :: # Import KNeighborsClassifier from sklearn.neighbors 
Python :: non blocking socket python 
Python :: Python NumPy asfarray Function Example List to float type array 
Python :: sort array numpy 
Python :: printing hello world in python 
Python :: na in python 
Python :: print something python 
Python :: how to access dictionary inside an array python 
Python :: call methods from within a class 
Python :: time complexity of remove in python 
Python :: remove timezone from column pandas 
Python :: python data first column indices 
Python :: python for loop inside list 
Python :: one line try except python 
Python :: how to make take command in python 
Python :: what does waka waka mean 
Python :: how to set pywal permenent 
Python :: stackoverflow ocr,cropping letters 
Python :: how to use list compression with conditional formatting 
Shell :: remove postgresql ubuntu 
Shell :: yarn emojis 
Shell :: docker install nano 
Shell :: Error starting daemon: error while opening volume store metadata database: timeout 
Shell :: commited to wrong branch 
Shell :: install nvm with brew 
Shell :: dns flush command 
Shell :: yarn clear cache 
ADD CONTENT
Topic
Content
Source link
Name
7+3 =