Concaténer des string en python sans espace

Exemples de code

0
0

ajouter un espace avant et après la chaîne de python

using re adds white-space before and after the desired characters:

import re

pat = re.compile(r"([.()!])")
print (pat.sub(" \\1 ", string))
# hello .  .  .   ( world )  ! 
0
0

chaîne de caractères sans espace pythonm

import re

string = '  Hello  World   From Pankaj \t\n\r\tHi There  '

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

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

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

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

Pages connexes

Pages d'exemples similaires

Dans d'autres langues

Cette page est dans d'autres langues

Русский
..................................................................................................................
English
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
हिन्दी
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................
Балгарскі
..................................................................................................................
Íslensk
..................................................................................................................