import re

s = 'asdf=5;iwantthis123jasd'
result = re.search('asdf=5;(.*)123jasd', s)
print(result.group(1))

# returns 'iwantthis'
Answer from Nikolaus Gradwohl on Stack Overflow
🌐
H2K Infosys
h2kinfosys.com › home › python tutorials › how to extract a string between two characters in python
How to Extract a String Between Two Characters in Python | H2K Infosys Blog
December 18, 2025 - Python’s built-in string methods like find() and index() can also be used for extracting substrings. ... text = "User (admin) logged in" start = text.find("(") + 1 end = text.find(")") substring = text[start:end] print(substring) # Output: admin · This method is similar to string slicing but uses the find() method to dynamically locate the indices of the characters.
Discussions

string - Get substring between two spesific characters in python - Stack Overflow
I am really confused that can't write a code that do this for me. Look This is my string: a="hello | my friends| in | stack | over | flow" I want to print "my friends" which is between first and More on stackoverflow.com
🌐 stackoverflow.com
Python coding : get string between two characters
I want to get a substring between two characters (/ and ?) from some url I have For example, I have : https://partners.doctolib.fr/vaccination-covid-19/rennes/centre-de-vaccination-covid-19-rennes-... More on github.com
🌐 github.com
2
1
python - How do I extract a substring between two characters using split()? - Stack Overflow
I'm having trouble taking out a substring located between the third occurrence of "." and the first occurrence of ":" in a line containing the word "foo". It would be More on stackoverflow.com
🌐 stackoverflow.com
getting string between 2 characters in python - Stack Overflow
I need to get certain words out from a string in to a new format. For example, I call the function with the input: text2function('$sin (x)$ is an function of x') and I need to put them into a More on stackoverflow.com
🌐 stackoverflow.com
🌐
PythonForBeginners.com
pythonforbeginners.com › home › how to split a string between characters in python
How to Split a String Between Characters in Python - PythonForBeginners.com
August 17, 2021 - Slice objects take three parameters: start, stop and step. The first two parameters tell Python where to start and end the slice, while the step parameter describes the increment between each step. With a slice object we can get a substring between characters.
🌐
Python Examples
pythonexamples.org › python-get-substring-between-two-characters
Python - Get substring between two specific characters
To get the substring between two ... Python, first find the index of first specific character, then find the index of second specific character that occurs after the first specific character, and finally with the two indices in hand, slice the string and find the required substring...
🌐
Java2Blog
java2blog.com › home › python › python string › get string between two characters in python
Get String Between Two Characters in Python - Java2Blog
November 28, 2022 - Use re’s search() method to get substring between two characters using regular expression, e.g.
🌐
EyeHunts
tutorial.eyehunts.com › home › python extract substring between two characters | example code
Python extract substring between two characters | Example code
April 29, 2022 - Apply re.search(pattern, string) with the pattern set to “x(.*?)y” to match substrings that begin with “x” and end with “y” and use Match.group() to get the desired substring.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-extract-string-between-two-substrings
Python - Extract string between two substrings - GeeksforGeeks
January 15, 2026 - Using the re module regular expressions allow flexible and efficient pattern matching to extract substrings between specified delimiters.
Find elsewhere
🌐
Python Guides
pythonguides.com › extract-a-substring-between-two-characters-in-python
How To Extract A Substring Between Two Characters In Python?
March 19, 2025 - We first find the index of the starting character index() and add its length to get the starting index of the substring. Then, we find the index of the ending character, starting from the previously found index. Finally, we use slice notation to extract the substring between these two indices. Read How to Fix Unterminated String Literals in Python?
🌐
stataiml
stataiml.com › posts › 32_extract_string_between_python
How to Extract String Between Two Characters or Strings in Python - stataiml
May 3, 2024 - You can extract a string between two characters or strings in Python using various functions such as search() (from re package) and split() functions.
🌐
Finxter
blog.finxter.com › home › learn python blog › python | split string between characters
Python | Split String Between Characters - Be on the Right Side of Change
November 30, 2022 - Simply put, you are finding the indices between which the required substring is present and then using string slicing to extract the required substring. ... # Given text = "Learn Python 3.9 from scratch" left = "Learn" right = "from scratch" start_index = text.find(left) + len(left) end_index = text.rfind(right) print(text[start_index:end_index]) # Python 3.9
🌐
Vitoshacademy
vitoshacademy.com › python-find-all-substrings-between-two-character-pairs-with-regex
Python – Find All Substrings Between Two Character Pairs with RegEx – Useful code
December 21, 2021 - And as visible, the character pairs will be these – Joe and Banana. As the last time I had to do this, the trivial task took me some solid 5 minutes, now I have decided to invest another 10 in writing this article, so hopefully in the long run I will save a minute or 2. Long story short – this is the function: import re def find_between(s, first, last): try: regex = rf'{first}(.*?){last}' return re.findall(regex, s) except ValueError: return -1 s = "Joe Ivan Banana, George Joe J.
🌐
GeeksforGeeks
geeksforgeeks.org › python-extract-string-between-two-substrings
Python – Extract string between two substrings | GeeksforGeeks
January 18, 2025 - A substring is any contiguous sequence of characters within the string. We'll discuss various methods to extract this substring from a given string by using a simple approach. Using List Comprehension :List comprehension offers a concise way to create lists by applying an expression to each element ... Python provides a powerful and flexible module called re for working with regular expressions.
🌐
PhoenixNAP
phoenixnap.com › home › kb › devops and development › how to substring a string in python
How to Substring a String in Python | phoenixNAP KB
November 27, 2025 - Python offers different ways to create substrings depending on the task. The examples in the sections below demonstrate various problems and walk through the code syntax to explain the behavior. To create a substring using slicing, refer to the following code: quote = "Toto, I have a feeling we're not in Kansas anymore." print(quote[6:22]) The code prints a substring between two characters at the provided indexes.
🌐
Stack Overflow
stackoverflow.com › questions › 75555352 › how-do-i-extract-a-substring-between-two-characters-using-split
python - How do I extract a substring between two characters using split()? - Stack Overflow
for line in myfile: if "foo" in line: substring = line.split(".", 3)[3].split(":")[0] print(substring) line = "a.b.c.d.e.f:foo" s = line.split('.', 3)[3] # "d.e.f:foo" s.split(':')[0] # d.e.f
🌐
Tutor Python
tutorpython.com › python-to-find-a-string-between-two-strings
3 Ways in Python to find a string between two strings - Tutor Python
April 25, 2024 - Another approach to extracting substrings between two other substrings within a larger string is by using the split method in Python.
🌐
pythoncodelab
pythoncodelab.com › home › python: get text between two strings, characters, or delimiters
Python: Get text between two strings, characters, or delimiters
January 14, 2026 - To get text between two characters we will use find() method in python. We will use the find() method twice, one for getting the first target character index and second one to get the last character index.
🌐
Reddit
reddit.com › r/learnpython › return the string between two characters
r/learnpython on Reddit: Return the String between two characters
July 21, 2022 -

I am trying to return the string between two characters.

entry_list = []
data = '<br>Hey</div> <br>Hey2</div>'
for i in data:
    a,b = data.split('<br>') 
    c,d = b.split(</div>)
    entry_list.append(c)
print('\n'.join(entry_list))

This code does not run.

How would I search a Python string, and return the value between <br> and </div> multiple times.