You need to use re.split if you want to split a string according to a regex pattern.

tokens = re.split(r'[.:]', ip)

Inside a character class | matches a literal | symbol and note that [.:] matches a dot or colon (| won't do the orring here).

So you need to remove | from the character class or otherwise it would do splitting according to the pipe character also.

or

Use string.split along with list_comprehension.

>>> ip = '192.168.0.1:8080'
>>> [j for i in ip.split(':') for j in i.split('.')]
['192', '168', '0', '1', '8080']
Answer from Avinash Raj on Stack Overflow
๐ŸŒ
PYnative
pynative.com โ€บ home โ€บ python โ€บ regex โ€บ python regex split string using re.split()
Python Regex Split String using re.split() โ€“ PYnative
July 27, 2021 - Using this pattern we can split string by multiple word boundary delimiters that will result in a list of alphanumeric/word tokens. Note: The \W is a regex special sequence that matches any Non-alphanumeric character. Non-alphanumeric means no letter, digit, and underscore.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ python โ€บ python-regex-split
Python - Regex split() - GeeksforGeeks
April 18, 2025 - import re s = "Geeks for Geeks" # Regular expression to match one or more non-word characters pattern = r'\W+' # Split the string using the pattern words = re.split(pattern, s) print(words) ... This regex \W+ splits the string at non-word characters.
Discussions

Split string based on RegEx in Python?
Post the input string you are regexing and what format it follows so we can help you come up with a regex. More on reddit.com
๐ŸŒ r/learnpython
14
1
January 2, 2023
python - Split string at every position where an upper-case word starts - Stack Overflow
What is the best way to split a string like "HELLO there HOW are YOU" by upper-case words? So I'd end up with an array like such: results = ['HELLO there', 'HOW are', 'YOU'] I have tried:... More on stackoverflow.com
๐ŸŒ stackoverflow.com
November 3, 2012
python - The result list contains single spaces when splitting a string with re.split("( )+") โ€“ is there a better way? - Stack Overflow
However there is no need for regex, str.split without any delimiter specified will split this by whitespace for you. This would be the best way in this case. ... Sign up to request clarification or add additional context in comments. ... Keep it simple. str.split is definitely the best :D 2012-06-11T06:07:17.07Z+00:00 ... How can I use this if I have a string ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
June 13, 2017
Split String every nth char / or the first occurrence of a period
If you want to split only on full sentences, just check for the location of the next full stop. If the phrase length is less than 15 characters, search for the subsequent full stop, check the length of both is still less than 15, and add it to the phrase. Repeat until the phrase is longer than 15 characters. More on reddit.com
๐ŸŒ r/java
8
0
August 28, 2013
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python
Split a String in Python (Delimiter, Line Breaks, Regex) | note.nkmk.me
May 4, 2025 - To split a string using a regular expression pattern, use the split() function from the re module. re.split() โ€” Regular expression operations โ€” Python 3.13.3 documentation ยท Pass the regex pattern as the first argument and the target string ...
๐ŸŒ
FavTutor
favtutor.com โ€บ blogs โ€บ python-split-regex
Python Split Regex: How to use re.split() function?
February 28, 2023 - Yes, you can use regular expressions in Python's split() method by passing a regex pattern as the delimiter parameter. Python's re module includes a split function for separating a text based on a pattern.
๐ŸŒ
Codecademy
codecademy.com โ€บ docs โ€บ python โ€บ regular expressions โ€บ re.split()
Python | Regular Expressions | re.split() | Codecademy
July 2, 2023 - The .split() method of the re module divides a string into substrings at each occurrence of the specified character(s). This method is a good alternative to the default .split() string method for instances that require matching multiple characters.
๐ŸŒ
Medium
medium.com โ€บ @abhishek8694 โ€บ exploring-advanced-string-splitting-techniques-with-pythons-regular-expressions-12c16231c013
Exploring Advanced String Splitting Techniques with Pythonโ€™s Regular Expressions | by Abhishek Mahajan | Medium
October 19, 2023 - The second approach, re.split(r'(;|,|\s)\s*', line1), takes a different approach. It retains the separator characters while still breaking the string into substrings. By using a capturing group (;) in the regular expression, we ensure that the separator characters themselves become part of the resulting list.
Find elsewhere
๐ŸŒ
Python Guides
pythonguides.com โ€บ python-split-string-regex
Python Split Regex [With Examples]
April 20, 2026 - By setting maxsplit=2, Python stops splitting after the second match, leaving the rest of the text as a single string. Usually, when you split a string, the delimiters are thrown away. But occasionally, I need to know which delimiter was used to split the text. To keep the delimiters, I wrap the regex pattern in parentheses ().
๐ŸŒ
Reddit
reddit.com โ€บ r/learnpython โ€บ split string based on regex in python?
r/learnpython on Reddit: Split string based on RegEx in Python?
January 2, 2023 -

I have a fairly big regex matching various types of common mail headers which are used between replies. I'm trying to use re.split to separate each reply as follows:

r = re.compile(r'((?:^ *Original Message processed by david.+?$\\n{,7})(?:.*\\n){,3}(?:(?:^|\\n)[* ]*(?:Von|An|Cc)(?:\\s{,2}).*){2,})|^(?!Am.*Am\\s.+?schrieb.*:)(Am\\s(?:.+?\\s?)schrieb\\s(?:.+?\\s?.+?):)$|((?:(?:^|\\n)[* ]*(?:From|Sent|To|Subject|Date|Cc):[ *]*(?:\\s{,2}).*){2,}(?:\\n.*){,1})|^(?!On[.\\s]*On\\s(.+?\\s?.+?)\\swrote:)(On\\s(?:.+?\\s?.+?)\\swrote:)$|(?:(?:^|\\n)[* ]*(Von|Gesendet|An|Betreff|Datum):[ *]*(?:\\s{,2}).*){2,}|(^(> *))', flags=re.MULTILINE)
r.split(text)

However I'm getting back a lot of None and mix between matches and the reply body content. Not so sure why โ€“ any idea? How I would imagine re.split to work:

[
    'Latest reply.', 
    'Am So., 1. Jan. 2023 um 17:22 Uhr schrieb John Doe <\nnoreply@github.com>:\n\n\nSecond reply\n', 
    ...
]

Sample data and regex: https://regex101.com/r/cC1FUo/1

๐ŸŒ
Python Tutorial
pythontutorial.net โ€บ home โ€บ python regex โ€บ python regex split()
Python Regex split()
December 10, 2021 - The built-in re module provides you with the split() function that splits a string by the matches of a regular expression. ... maxsplit determines at most the splits occur. Generally, if the maxsplit is one, the resulting list will have two elements. If the maxsplit is two, the resulting list ...
๐ŸŒ
Python Examples
pythonexamples.org โ€บ python-split-string-by-regex
How to Split String by Regular Expression in Python?
import re #a string str = 'foo635bar4125mango2apple21orange' #split with regular expression chunks = re.split('\d+',str) print(chunks) ... In this tutorial of Python Examples, we learned how to re package to split a string using regular expressions.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python | split string with regex
Python | Split String with Regex - Be on the Right Side of Change
December 13, 2022 - The re.split(pattern, string) method matches all occurrences of the pattern in the string and divides the string along the matches resulting in a list of strings between the matches.
๐ŸŒ
Finxter
blog.finxter.com โ€บ home โ€บ learn python blog โ€บ python regex split
Python Regex Split - Be on the Right Side of Change
November 23, 2022 - Return Value: The regex split method returns a list of substrings obtained by using the regex as a delimiter. ๐Ÿ’ก Info: The re.split() method is used in practice to perform complex string splitting operations such as splitting a string by Uppercase ...
๐ŸŒ
TechGeekBuzz
techgeekbuzz.com โ€บ blog โ€บ python-regex-split-string-using-re-split
Python Regex Split String Using re.split()
And the \s+ matches the multiple white spaces in the string, and we will use it as a pattern to split our string into a list of words. import re #pattern sequence for multiple white space pattern = r'\s+' #targeted string string = "Hello Welcome to TechGeekBuzz Python RegEX Tutorial" #split the string by white spaces word_list = re.split(pattern, string) print(word_list)
๐ŸŒ
YouTube
youtube.com โ€บ watch
#77 How to Split String in Python Using Regex | Regular Expression Python - YouTube
Learn to split string using regex in python. The split method takes a string or regular expression and splits the string based on the provided separator, int...
Published ย  July 16, 2022
๐ŸŒ
YouTube
youtube.com โ€บ datadaft
Python Regex: How To Split a String On Multiple Characters - YouTube
โ†“ Code Available Below! โ†“ This video shows how to split a string of text based on multiple characters at the same time using the regular expressions package ...
Published ย  October 1, 2020
Views ย  309
๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ article โ€บ How-can-I-use-Python-regex-to-split-a-string-by-multiple-delimiters
How can I use Python regex to split a string by multiple delimiters?
November 2, 2023 - The built-in regular expression library re is the easiest way to divide a string. The library has a.split() function that works similarly to the above example. This approach stands out since it lets you separate our strings using regular expressions. This article taught you how to divide a Python string using several delimiters.