0

I have the following HTML:

<i>This is my first sentence.        

This is my second sentence.</i>

Using Regex (in SublimeText FYI) how can I select only the whitespace (including line breaks) between the two <i></i> brackets?

I have got this far where I can select all the characters, but how do I limit it to whitespace and new lines only?:

(?<=<i.).*?(?=</i>)

https://regex101.com/r/eZ1gT7/1986

1
  • 3
    A regexp can only match a contiguous substring, it can't match unconnected substrings. Commented Jul 16, 2019 at 21:38

3 Answers 3

1

You can not do it with single regex, you can use a combination of regex

  1. <\s*i[^>]+>([\s\S]+?)<\s*\/\s*i\s*>

Demo

This will give you values between tags <i> and text between tags is available in captured group 1, now you can loop through the matched values and find any space character

  1. \s+
Sign up to request clarification or add additional context in comments.

Comments

0

I'm guessing that maybe this expression,

(?=\s*[\n\r])(\s*)(?=\S)

replaced with a single space () might be close to what you might have in mind.


The expression is explained on the top right panel of this demo if you wish to explore/simplify/modify it.

Comments

0

You'll have to loop through the captured group 2: (<i[^>]+?>)?([ \n]*)(<\/i>)?

https://regex101.com/r/wcPwkU/1

Comments

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.