I'd like to remove all characters before a designated character or set of characters (for example):
intro = "<>I'm Tom."
Now I'd like to remove the <>
before I'm
(or more specifically, I
). Any suggestions?
To remove everything before the first occurrence of the character '-' in a string, pass the character '-' as separator and 1 as the max split value. The split('-', 1) function will split the string into 2 parts, Part 1 should contain all characters before the first occurrence of character '-'.
Use the String. slice() method to remove everything after a specific character, e.g. const removed = str. slice(0, str. indexOf('[')); .
Use the split() method to cut string after the character in Python.
Use re.sub
. Just match all the chars upto I
then replace the matched chars with I
.
re.sub(r'^.*?I', 'I', stri)
str.find
could find character index of certain string's first appearance
:
intro[intro.find('I'):]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With