Python Regex: How To Split a String On Multiple Characters

preview_player
Показать описание
↓ Code Available Below! ↓

If you find this video useful, like, share and subscribe to support the channel!

Code used in this Python Code Clip:

import re

# Default python split works on a single character

string = lines)

* Note: YouTube does not allow greater than or less than symbols in the text description, so the code above will not be exactly the same as the code shown in the video! I will use Unicode large < and > symbols in place of the standard sized ones. .

Рекомендации по теме
Комментарии
Автор

Code Used in this Video:

import re

lines = as|separators'''

# Default python split works on a single character
lines.split()

# Use re.split() to split on several different characters
re.split(pattern = r"[-_\|\.\+ ]",
string = lines)

DataDaft
Автор

Really great video, I am looking forward to the next one!

valda
Автор

Gret, what if i want to get only word before hyphen how should I get the, suppose the word is day-off and only want to get day using the split function

TheChadtech
Автор

In my Data Frame I have a series called PackSize that has a mixture of packs, however some have a space between the number and the textual pack and others don't, i.e. '10 kg', '12.5kg', '4.5 Ltr', '5000ml', etc.... Would you recommend using regex and if so what would be the syntax to use - I am new to pandas!

darrentecklenberg
Автор

exactly what i needed. thanks for the information

marcusanderson
Автор

How can you tell it to split on a period but only if it is preceded with no white space and followed by white space?

KrazyMO
Автор

Thank you very much. I am stick to your channel and big fan of what you introduce.

KhalilYasser
Автор

What about splitting on multiple keywords instead of symbol delimiters?

vio-noob_