From the docs:

str.split([sep[, maxsplit]])

Return a list of the words in the string, using sep as the delimiter string. If maxsplit is given, at most maxsplit splits are done (thus, the list will have at most maxsplit+1 elements).

s.split('mango', 1)[1]
Answer from Ignacio Vazquez-Abrams on Stack Overflow
🌐
Finxter
blog.finxter.com › home › learn python blog › python split string at first occurrence
Python Split String at First Occurrence - Be on the Right Side of Change
November 23, 2022 - ⚡Summary: Use given_string.split('sep', 1) to split the string at the first occurrence of a given delimiter. Another approach to solve the problem is to use given_string.partition('sep'). Minimal Example Problem Formulation 📜Problem: Given a string. How will you split the string at the ...
Discussions

I want to split a string by a character on its first occurence, which belongs to a list of characters. How to do this in python? - Stack Overflow
Basically, I have a list of special characters. I need to split a string by a character if it belongs to this list and exists in the string. Something on the lines of: def find_char(string): if More on stackoverflow.com
🌐 stackoverflow.com
arrays - How can I split a string at the first occurrence of a letter in Python? - Stack Overflow
A have a series of strings in the following format. Demonstration examples would look like this: 71 1 * abwhf 8 askg *14 snbsb 00ab I am attempting to write a Python 3 program that will use a ... More on stackoverflow.com
🌐 stackoverflow.com
split - Python - Cut string based on first occurrence of characters in list - Stack Overflow
I have some values in column like data1 = "any_number_of_characters&wanted=gsjgj87-hdjh_66&" data2 = "any_number_of_characters&wanted=g232gj87-hdjh_66#dhvdhohoh" dat... More on stackoverflow.com
🌐 stackoverflow.com
python - How can i split a string into two on the first occurrence of a character - Stack Overflow
I have written a code to list all the components in my Linux server. The list is stored in a file. I will ready line by line and have to split the components from version and store in 2 different s... More on stackoverflow.com
🌐 stackoverflow.com
July 20, 2016
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-seperate-first-word-from-string
Python - Separate first word from String - GeeksforGeeks
July 12, 2025 - We can also use the partition() method, which splits the string into three parts: everything before the first occurrence of the separator (space), the separator itself, and everything after it.
Top answer
1 of 1
4

I would favor using the re module for this because the expression for splitting on multiple arbitrary characters is very simple:

r'[,*;/]'

The brackets create a character class that matches anything inside of them. The code is like this:

import re

results = re.split(r'[,*;/]', my_string, maxsplit=1)

The maxsplit argument makes it so that the split only occurs once.

If you are doing the same split many times, you can compile the regex and search on that same expression a little bit faster (but see Jon Clements' comment below):

c = re.compile(r'[,*;/]')
results = c.split(my_string)

If this speed up is important (it probably isn't) you can use the compiled version in a function instead of having it re compile every time. Then make a separate function that stores the actual compiled expression:

def split_chars(chars, maxsplit=0, flags=0, string=None):
    # see note about the + symbol below
    c = re.compile('[{}]+'.format(''.join(chars)), flags=flags)
    def f(string, maxsplit=maxsplit):
        return c.split(string, maxsplit=maxsplit)
    return f if string is None else f(string)

Then:

special_split = split_chars(',*;/', maxsplit=1)
result = special_split(my_string)

But also:

result = split_chars(',*;/', my_string, maxsplit=1)

The purpose of the + character is to treat multiple delimiters as one if that is desired (thank you Jon Clements). If this is not desired, you can just use re.compile('[{}]'.format(''.join(chars))) above. Note that with maxsplit=1, this will not have any effect.

Finally: have a look at this talk for a quick introduction to regular expressions in Python, and this one for a much more information packed journey.

🌐
IQCode
iqcode.com › code › python › python-split-on-first-occurrence
python split on first occurrence Code Example
str.split([sep[, maxsplit]]) s = "123mango abcd mango kiwi peach" s.split("mango", 1) ['123', ' abcd mango kiwi peach'] >>> s.split("mango", 1)[1] ' abcd mango kiwi peach' ... Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
🌐
LinkedIn
linkedin.com › pulse › how-do-i-split-string-first-instance-character-python-clcoding
How do I split a string at the first instance of a character in Python?
October 31, 2021 - s = "Python Programming" k = input("Enter character at which you want to split") #It returns the index of first occurence of character k · i = s.index(k) print('First Part:- ', s[:i]) print('Second Part:- ', s[i+1:]) Like · Like · Celebrate · Support · Love ·
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-split-string-on-kth-occurrence-of-character
Split string on Kth Occurrence of Character - Python - GeeksforGeeks
July 12, 2025 - After the Kth occurrence, append the rest of the string starting from the next character · re.split() method in Python allows splitting a string based on a regular expression pattern.
🌐
Plain English
python.plainenglish.io › how-to-split-a-string-on-the-first-n-occurrences-in-python-827592db0130
How to Split a String on the First N Occurrences in Python | Python in Plain English
June 14, 2022 - Another example of this way of turning a string into a list of strings can be when doing the splitting using commas: This is something quite known and widespread. What is not that much known is the fact that the method split() can actually take a second argument that indicates the number… ... New Python content every day.
🌐
Stack Overflow
stackoverflow.com › questions › 65124340 › python-cut-string-based-on-first-occurrence-of-characters-in-list
split - Python - Cut string based on first occurrence of characters in list - Stack Overflow
You could search the any of the stop characters after wanted that is closest to the string you are searching for: data1 = "any_number_of_characters&wanted=gsjgj87-hdjh_66&" data2 = "any_number_of_characters&wanted=g232gj87-hdjh_66#dhvdhohoh?uhdjd=skjhnknkn" data3 = "any_number_of_characters&wanted=gsjgj87-hdjh_66?uhdjd=skjhnknkn#dhvdhohoh" def extractData(data, startPattern, endCharacters='&#?'): start = data.find(startPattern) end = min( [ pos if -1 < (pos := data.find(ec, start + 1)) > start else len(data) for ec in list(endCharacters) ] ) return (data[start + len(startPattern):end]) for data in (data1, data2, data3): print(extractData(data, 'wanted='))
🌐
Quora
clcoding.quora.com › How-to-split-a-string-at-the-first-instance-of-a-character-in-Python
How to split a string at the first instance of a character in Python - Python Coding - Quora
Quora is a place to gain and share knowledge. It's a platform to ask questions and connect with people who contribute unique insights and quality answers.
🌐
Simplilearn
simplilearn.com › home › resources › software development › python split() function: how to use split() in python
Python split() Function: Syntax, and Usage Guide
July 31, 2025 - The split() function in Python can be used to split a given string or a line by specifying one of the substrings of the given string as the delimiter.
Address: 5851 Legacy Circle, 6th Floor, Plano, TX 75024 United States
🌐
Python Morsels
pythonmorsels.com › string-split-method
The string split method in Python - Python Morsels
September 27, 2024 - When calling split with a maxsplit value, Python will split the string a given number of times. So here we're splitting this string on a pipe character (|) just one time: >>> line = "Rubber duck|5|10" >>> line.split("|", maxsplit=1) ['Rubber duck', '5|10'] This is especially handy when you only care about the first or the first couple occurrences ...
🌐
Reddit
reddit.com › r/learnpython › method like rstrip() but only performs once?
r/learnpython on Reddit: method like rstrip() but only performs once?
November 19, 2020 -

I am currently making a project for university and I'm having a problem making a code for the method I'm finding.

I am finding a method to remove a specified character sc from a string. But for strings that contain more than 1 occurrence of the sc, only one occurrence of the sc should be removed from the right.

Example:

before_string = "abcdefaghsjsajs"

sc = "a"

after_string = "abcdefaghsjsjs"

I have tried using the replace() method. It works very well with my code, especially because I can tell it to only remove 1 occurrence of the sc. However, it doesn't work when there is more than 1 occurrence of the sc because it removes the sc from the left and not from the right.

Does anyone have any idea? Thank you.

🌐
Real Python
realpython.com › python-split-string
How to Split a String in Python – Real Python
February 5, 2025 - The .split() method in Python is a versatile tool that allows you to divide a string into a list of substrings based on a specified delimiter. By default, .split() separates a string at each occurrence of whitespace, which includes spaces, tabs, ...
🌐
PYnative
pynative.com › home › python › regex › python regex split string using re.split()
Python Regex Split String using re.split() – PYnative
July 27, 2021 - Here we will use the \D special sequence that matches any non-digit character. ... import re target_string = "12-45-78" # Split only on the first occurrence # maxsplit is 1 result = re.split(r"\D", target_string, maxsplit=1) print(result) # Output ['12', '45-78'] # Split on the three occurrence # maxsplit is 3 result = re.split(r"\D", target_string, maxsplit=3) print(result) # Output ['12', '45', '78']Code language: Python (python) Run