For Python 3.9+:

text.removeprefix(prefix)

For older versions, the following provides the same behavior:

def remove_prefix(text, prefix):
    if text.startswith(prefix):
        return text[len(prefix):]
    return text
Answer from Elazar on Stack Overflow
🌐
Python
peps.python.org › pep-0616
PEP 616 – String methods to remove prefixes and suffixes | peps.python.org
March 19, 2020 - Within the tuple, only the first matching affix would be removed. This was rejected on the following grounds: This behavior can be surprising or visually confusing, especially when one prefix is empty or is a substring of another prefix, as in 'FooBar'.removeprefix(('', 'Foo')) == 'FooBar' or 'FooBar text'.removeprefix(('Foo', 'FooBar ')) == 'Bar text'.
Discussions

regex - How to remove the prefix from each element of python list? - Stack Overflow
I have a python list with items as follows: [ 1.1 ] 1. a electronic bill presentment system. [ 1.2 ] a network. [ 1.3 ] a plurality of first stations, each associated with a respective one of a More on stackoverflow.com
🌐 stackoverflow.com
Finally a remove prefix, sufix string method in Python 3.9
This strikes me as bloat since replace() and rfind() can be used already. related to user confusion about the existing str.lstrip and str.rstrip methods This is a user issue, not a language issue. It is stated quite clearly in documentation what those functions do. Why add in a crutch because people can't read? https://docs.python.org/3/library/stdtypes.html#str.lstrip LITERALLY STATES: "The chars argument is not a prefix; rather, all combinations of its values are stripped" https://docs.python.org/3/library/stdtypes.html#str.rstrip Again, LITERALLY STATES: "The chars argument is not a suffix; rather, all combinations of its values are stripped" several users on Python-Ideas [2] reported frequently including similar functions in their code for productivity. The implementation often contained subtle mistakes regarding the handling of the empty string, so a well-tested built-in method would be useful. Again, that's a user issue and not a language issue in my opinion. or to use regular expressions as in the expression re.sub('' + re.escape(prefix), '', s) Really ?! More on reddit.com
🌐 r/Python
5
10
April 21, 2020
regex - Remove prefix from name python - Stack Overflow
names = [ 'LIC. SEBASTIÁN LASTIRI', 'ING. AGR. ROBERTO DANIEL RODRÍGUEZ', 'C.P.N. JULIO DOMINGO BURAK', 'INGENIERO HIDRÁULICO VÍCTOR AGUSTÍN PORRINO' ] I have such list with names, i need to remove More on stackoverflow.com
🌐 stackoverflow.com
April 1, 2015
how to remove part of a file name recursively in python?
What you want to do is remove the prefix. Your prefix is 31 chars >>> len("The.Simpsons.The.Simpsons.clear") 31 >>> t="The.Simpsons.The.Simpsons.clearThe.SimpsonsSeason 1 EP7 The Call of the Simpsons.mkv" >>> t[31:] 'The.SimpsonsSeason 1 EP7 The Call of the Simpsons.mkv' A bit of advice: before you do something permanent like renaming files, print out new names just to make sure they look ok. More on reddit.com
🌐 r/learnpython
7
9
March 8, 2015
🌐
Stack Abuse
stackabuse.com › python-remove-the-prefix-and-suffix-from-a-string
Python: Remove the Prefix and Suffix From a String
March 7, 2023 - After verifying that the prefix exists, we slice the string to contain everything but the prefix and return the results. This gives the following output where the prefix "xy" is removed from the string: $ python remove_prefix_alt.py Before: xyxyxyxyxy | yzyzyzyzyz 5 After: xyxyxyxy | yzyzyzyzyz 4
🌐
GeeksforGeeks
geeksforgeeks.org › python-string-removeprefix-function
Python String - removeprefix() function - GeeksforGeeks
December 5, 2024 - Python String removeprefix() function removes the prefix and returns the rest of the string.
🌐
GeeksforGeeks
geeksforgeeks.org › python-remove-prefix-strings-from-list
Python | Remove prefix strings from list - GeeksforGeeks
April 11, 2023 - In this, we don't perform removal in place, instead, we recreate the list without the elements that match the prefix. ... # Python3 code to demonstrate working of # Remove prefix strings from list # using list comprehension + startswith() # initialize list test_list = ['xall', 'xlove', 'gfg', 'xit', 'is', 'best'] # printing original list print("The original list : " + str(test_list)) # initialize prefix pref = 'x' # Remove prefix strings from list # using list comprehension + startswith() res = [ele for ele in test_list if not ele.startswith(pref)] # printing result print("List after removal of Kth character of each string : " + str(res))
Find elsewhere
🌐
Note.nkmk.me
note.nkmk.me › home › python
Remove a Substring from a String in Python | note.nkmk.me
April 23, 2025 - Contents · Remove a substring ... characters: lstrip() Remove trailing characters: rstrip() Remove prefix: removeprefix() (Python 3.9 or later) Remove suffix: removesuffix() (Python 3.9 or later) Remove a substring by position ...
🌐
Learn by Example
learnbyexample.github.io › tips › python-tip-10
Python tip 10: removeprefix and removesuffix string methods
May 11, 2022 - # remove 'sp' if it matches at the start of the input string >>> 'spare'.removeprefix('sp') 'are' # 'par' is present in the input, but not at the start >>> 'spare'.removeprefix('par') 'spare' # remove 'me' if it matches at the end of the input string # only one occurrence of the match will be removed >>> 'this meme'.removesuffix('me') 'this me' # characters have to be matched exactly in the same order >>> 'this meme'.removesuffix('em') 'this meme'
🌐
datagy
datagy.io › home › python posts › python strings › how to remove a prefix or suffix from a string in python
How to Remove a Prefix or Suffix from a String in Python • datagy
December 16, 2022 - How to use string slicing to remove a prefix or a suffix ... If you are using Python 3.9 or later, the best way to remove a suffix from a string in Python is to use the .removeprefix() method.
🌐
E1515
e1515.com.tw › post › python-remove-prefix
python remove prefix
December 11, 2024 - This example uses re.sub() to remove any leading sequence of digits followed by an underscore (^\d+_). The ^ anchors the match to the beginning of the string. This flexibility makes regular expressions ideal for handling diverse prefix structures.
🌐
Codecademy
codecademy.com › docs › python › strings › .removeprefix()
Python | Strings | .removeprefix() | Codecademy
August 28, 2025 - The .removeprefix() method is a built-in string method that returns a new string with the specified prefix removed, if present. If the string does not start with the given prefix, the original string is returned unchanged.
Top answer
1 of 4
3

Here's one approach using re.sub:

import re
l = ['[ 1.1 ] 1. a electronic bill presentment system.','[ 1.2 ] a network.']

[re.sub(r'\[\s*\d+\.*\d*\s*\]\s+(?:\d+\.\s*)?', '', s) for s in l]
# ['a electronic bill presentment system.', 'a network.']

See demo


Testing with a larger list of strings:

l = ['[ 1.1 ] 1. a electronic bill presentment system.',\
'[ 1.2 ] a network.',\
'[ 1.3 ] a plurality of first stations, each associated with a respective one of a plurality of users and operable to transmit first requests for bills of its associated user via the network.',\
'[ 1.5 ] a plurality of second network stations, each associated with a respective one of a plurality of billers, configured to receive the transmitted second requests for bills and to transmit, responsive thereto, the requested bills of the associated user via the network.',\
'[ 1.6 ] wherein the bill availability information for the associated user identifies those of the plurality of billers having a bill available for that user without identifying an amount of the bill of each of the identified billers for the associated user.',\
'[ 2.1 ] 2. a method for presenting electronic bills.']

[re.sub(r'\[\s*\d+\.*\d*\s*\]\s+(?:\d+\.\s*)?', '', s) for s in l]

['a electronic bill presentment system.',
 'a network.',
 'a plurality of first stations, each associated with a respective one of a plurality of users and operable to transmit first requests for bills of its associated user via the network.',
 'a plurality of second network stations, each associated with a respective one of a plurality of billers, configured to receive the transmitted second requests for bills and to transmit, responsive thereto, the requested bills of the associated user via the network.',
 'wherein the bill availability information for the associated user identifies those of the plurality of billers having a bill available for that user without identifying an amount of the bill of each of the identified billers for the associated user.',
 'a method for presenting electronic bills.']
2 of 4
2

You should regular expression to substitute the pattern with an empty string

>>> re.sub(r'\[\s?\d\.\d\s?]\s?(\d(\.\s)?)?', '', '[ 1.1 ] 1. a electronic bill presentment system.')
'a electronic bill presentment system.'
🌐
Runebook.dev
runebook.dev › en › docs › python › library › stdtypes › str.removeprefix
A Friendly Guide to Python's removeprefix(): Pitfalls and Sample Code
I'll be referring to the method as removeprefix() to keep it simple!The removeprefix() method was introduced in Python 3.9. It removes a specified prefix string from the start of the original string
🌐
Medium
medium.com › @asierr › pythons-str-removeprefix-and-str-removesuffix-finally-a-cleaner-way-to-modify-strings-468ee7114eb5
Python's str.removeprefix() and str.removesuffix(): Finally, a ...
February 18, 2025 - Python’s str.removeprefix() and str.removesuffix(): Finally, a Cleaner Way to Modify Strings For years, Python developers have relied on slicing or regular expressions to remove prefixes and …
🌐
Reddit
reddit.com › r/python › finally a remove prefix, sufix string method in python 3.9
r/Python on Reddit: Finally a remove prefix, sufix string method in Python 3.9
April 21, 2020 - https://docs.python.org/3/library/stdtypes.html#str.lstrip · LITERALLY STATES: "The chars argument is not a prefix; rather, all combinations of its values are stripped"
🌐
Kieran Barker
barker.codes › blog › removing-prefixes-and-suffixes-in-python
Removing prefixes and suffixes in Python - Kieran Barker
January 16, 2023 - Not only is this more readable, ... ≤ 3.8, the easiest way to remove a prefix (or suffix) from a string is to check if the string starts with the prefix (or ends with the suffix) and slice it....
🌐
Finxter
blog.finxter.com › home › learn python blog › how to remove the prefix of a string in python?
How To Remove The Prefix Of A String In Python? - Be on the Right Side of Change
March 23, 2021 - For example, my_string.removeprefix('xxx') removes the prefix 'xxx' from my_string. >>> 'xxxhello world'.removeprefix('xxx') 'hello world' Note: All the solutions provided below have been verified using Python 3.9.0b5
🌐
All About AI-ML
indhumathychelliah.com › 2020 › 10 › 12 › new-string-methods-to-remove-prefixes-and-suffixes-in-python-3-9
New String Methods to Remove Prefixes and Suffixes in Python 3.9 – All About AI-ML
January 2, 2022 - removeprefix,removesuffix → only at most one copy of prefix/suffix is removed. lstrip,rstrip → the characters are repeatedly removed from the beginning/end of the string.