Using python I’m parsing several strings. Sometimes the string has appended several semicolons to it.
Example strings:
s1="1;Some text"
s2="2;Some more text;;;;"
The number of appending semicolons varies, but if it’s there it’s never less than two.
The following pattern matches s1, with s2 it includes the appended semicolons.
How do I redo it to remove those?
pat=re.compile('(?m)^(\d+);(.*)')
You can use the
str.rstrip([chars])This method returns a copy of the string in which all chars have been stripped from the end of the string (default whitespace characters).
e.g. you can do:
You can find more information here.