Search code examples
pythontextblogs

How to extract text between two markers?


I am trying to create a blogging site kind of like medium.com. The only problem I am facing is the headings in the blog. I want to do what stack overflow does with bold text.

**text**

But I can't seem to figure out how to make this. Sorry if this question is not detailed enough and Thanks for giving this question your time.


Solution

  • you can find string between two subStrings using python regular expression.

    import re
    s = '**text**'
    result = re.search('\*\*(.*)\*\*', s)
    print(result.group(1)) #output :==> text
    

    you really should learn regular expression 😀.