Simple python script to extract sub string between two delimiters of a string. Examples of delimiters are brackets, parentheses, braces, single or double quotes etc. You can also customize this code to extract the string between two special characters or two sub strings. Comments on each line of code explains you to easily understand the code.
Note: This code is written in Python 2
string = "sri[nivas]silveri" firstDelPos=string.find("[") # get the position of delimiter [ secondDelPos=string.find("]") # get the position of delimiter ] extractedString = string[firstDelPos+1:secondDelPos] # get the string between two dels print extractedString # print the extracted string between two dels
Python: Replace/remove string between two delimiters/characters