1

How could I match a text between a span opening and closing tags with style attribute?:

<span style="white-space: pre-line">some text</span>

I tried the following pattern but it doesn't work:

<span style=\"white-space: pre-line\">(.*)</span>
4
  • 1
    Are you asking us for a regex? If so then lookup the look behind and lookahead assertations Commented Jun 8, 2016 at 7:34
  • Actually I understand that it's a bad idea to search html with a regex. Now I'm looking how to convert html text to a plain one. Commented Jun 8, 2016 at 9:18
  • 1
    I would suggest suing the nuget package: HTML Agility Pack nuget.org/packages/HtmlAgilityPack. It makes HTML traversal very easy Commented Jun 8, 2016 at 9:20
  • Thanks for suggesting. Commented Jun 8, 2016 at 12:18

1 Answer 1

2

First of all, it is in general a bad idea to parse HTML with a Regex.

It would be better to use a solution to parse HTML, like HTML Agility Pack.

That said, if you need help with Regular Expressions, you can download a tool that will help you analyze and test them. There are several tools available for that, I personally like Expresso.

In this particular case, I think you are having problems with the spaces, but I cannot be sure since you are not showing the RegexOptions you are using to build your Regex. Try

<span\s*style=\"white-space:\s*pre-line\">(.*)</span>
Sign up to request clarification or add additional context in comments.

2 Comments

@MaximilianAst: why should it be necessary to escape the /?
Sry my bad. Forgot that / hasn't to be escaped in .NET

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.