Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR 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
Source by www.journaldev.com #
 
PREVIOUS NEXT
Tagged: #string #space #pythonm
ADD COMMENT
Topic
Name
8+6 =