Use the split method of string.See the below code snippet. string = "" Why did DOS-based Windows require HIMEM.SYS to boot? The technical storage or access is necessary for the legitimate purpose of storing preferences that are not requested by the subscriber or user. Therefore when specifying the pattern of our regular expression, we can simply provide a semicolon and comma within square brackets and an additional space [;,] which would result in the regular expression being matched by parts of a string with exactly [a semicolon OR comma] and a trailing space. Use regular expressions: import re Index of markers has been sotred in var mk1 and mk2 using the find() method. Method #1: Using index () + loop to extract string between two substrings In this, we get the indices of both the substrings using index (), then a loop is used to iterate re.findall() returns a list of all matching substrings. )\\] and match the given string with the Regular Expression. As it is the last element, it can be specified as [-1]. )\\] and match the given string with the Regular Expression. Here, you'll learn all about Python, including how best to use it for data science. We have used Python 3.10.1 for writing example codes. world Python string split() method allows a string to be easily split into a list based on a delimiter. Split a Python String on Multiple Delimiters using Regular Expressions, Split a Python String on Multiple Delimiters using String Split, Create a Function to Split a Python String with Multiple Delimiters, comprehensive overview of Pivot Tables in Pandas, Python Optuna: A Guide to Hyperparameter Optimization, Confusion Matrix for Machine Learning in Python, Pandas Quantile: Calculate Percentiles of a Dataframe, Pandas round: A Complete Guide to Rounding DataFrames, Python strptime: Converting Strings to DateTime. To learn more, see our tips on writing great answers. Welcome to datagy.io! 566), Improving the copy in the close modal and post notices - 2023 edition, New blog post from our CEO Prashanth: Community is the future of AI. Which was the first Sci-Fi story to predict obnoxious "robo calls"? Extract substrings between any pair of delimiters For example, [a-z] matches any one character of the lowercase alphabet. We pass in the pipe character|as anorstatement. It should be noted that this method is not recommended when used for higher delimiter counts such as in this instance. For our example, we need to split it either by a semicolon followed by a space ; , or by a comma followed by a space , . I'm learning and will appreciate any help. string = '' For every ] encountered, simply pop the index stored at the top of the stack and print the substring lying in between.