Get string between two strings

get string between two strings python
get string between two strings javascript
c# get string between two strings regex
get string between two strings php
python extract string between delimiters
python regex string between two characters
how to get string between two strings in c# using regex
php get string between two strings regex
<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>

How would I get the string between the first two paragraph tags? And then, how would I get the string between the 2nd paragraph tags?

Regular expressions

import re
matches = re.findall(r'<p>.+?</p>',string)

The following is your text run in console.

>>>import re
>>>string = """<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"""
>>>re.findall('<p>.+?</p>',string)
["<p>I'd like to find the string between the two paragraph tags.</p>", '<p>And also this string</p>']

How to extract a string lies between two strings in C#.Net?, This is a simple blog that shows how to extract a string from a sentence between two given strings. Assuming that you have a list of data in range B1:B5, in which contain text string values. And you need to extract all text strings between two words “excel” and “learning” in cells. You can use a formula based on the MID function, the SEARCH function, and the Len function to extract text between two specified strings. Like this:

If you want the string between the p tags (excluding the p tags) then add parenthesis to .+? in the findall method

import re
    string = """<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"""
    subStr = re.findall(r'<p>(.+?)</p>',string)
    print subStr

Result

["I'd like to find the string between the two paragraph tags.", 'And also this string']

C# String Between, Before, After, We search for substrings between two strings, before a string or after a string. class SubstringExtensions { /// <summary> /// Get string value between [first] a  $arr=explode (separator, string). This will return an array which will contain the string split on the basis of the separator. Split the list on the basis of the starting word. In the returned array the 2nd index will contain the words after the start word.

In between <p> and </p>

In [7]: content = "<p>I'd like to find the string between the two paragraph tags.</p><br><p>And also this string</p>"

In [8]: re.findall(r'<p>(.+?)</p>', content)
Out[8]: 
["I'd like to find the string between the two paragraph tags.",
 'And also this string']

How to get the substring between two markers in Python, How do I extract a string between two strings in python? Dim res As String = Strings.Mid(sSource, sDelimStart.Length + 1, sSource.Length - (sDelimStart.Length + sDelimEnd.Length)) Strings.Mid(string to get middle part from, startIndex, lenght)

How to extract a particular word from a string in C#, How do I extract a specific word from a string in C#? These solutions assume the start string and final string are different. Here is a solution I use for an entire file when the initial and final indicators are the same, assuming the entire file is read using readlines():

C# | String.IndexOf( ) Method, sub = testString. Substring(testString. IndexOf("Mail:") + 5); Console. WriteLine(sub); I have to add something to the post of Julius Tilvikas. I looked for a solution like this one he described in his post. But i think there is a mistake. I don't get realy the string between two string, i also get more with this solution, because i have to substract the lenght of the start-string. When do this, i realy get the String between two

How to extract string between two different characters in Excel?, How do I find a word in a string C#? First method: is to actually get a substring from between two strings (however it will find only one result). Second method: will remove the (would-be) most recently found result with the substrings after and before it. Third method: will do the above two methods recursively on a string. Fourth method: will apply the third method and return the

Comments
  • I've given you an upvote, but please correct these misspells in frirst fragment. Should be </p>
  • This might sound stupid but how come this doesn't work? split = re.findall('<p>.+?</p>',content) ...... second = split[1]......it gives me an index out of range error. How do I get the 2nd element?
  • @Zorgan, could you have changed the content? it works in my console: >>> split = re.findall('<p>(.+?)</p>',string) >>> split[1] 'And also this string'
  • Yeah it was my content, i've fixed it now. Thanks.
  • Superb. Just what I needed.