user1249791
user1249791

Reputation: 1271

sublime text regex multiple parameters

I want to take Parameter1 using regex in Sublime Text. Other parameter will not be used.

Initial tags:

<description><![CDATA[<b>Parameter1</b></br></br> 
This not to be copied and can be long]]></description>

This expression in Regex Sublime Text...

<description><!\[CDATA\[<b>(\w+)</b></br></br>(\w*)\]\]</description>

cannot find what I need (when I reach it stops finding)

Upvotes: 0

Views: 213

Answers (1)

user557597
user557597

Reputation:

Your regex doesn't match the test string.
There are whitespaces between the word letters.
It also won't match non-word letters like punctuation.

Below are two Regexs'

1. This is just to match your test string.

 # <description>\s*<!\[CDATA\[\s*<b>([\s\w]+)</b>\s*</br>\s*</br>([\s\w]*)\]\]\s*</description>

 <description>
 \s* 
 <!\[CDATA\[
 \s* 
 <b>
 (                                 # (1)
      [\s\w]+ 
 )
 </b> \s* </br> \s* </br>
 (                                 # (2)
      [\s\w]* 
 )
 \]\]
 \s* 
 </description>

2. This is how it should be done if your engine supports lookahead assertions.

 # (?s)<description>\s*<!\[CDATA\[\s*<b>((?:(?!\]\]|\s*</b>).)+?)\s*</b>\s*</br>\s*</br>\s*((?:(?!\s*\]\]).)*)\s*\]\]\s*</description>

 (?s)
 <description>
 \s* 
 <!\[CDATA\[
 \s* 
 <b>
 (                                 # (1)
      (?:
           (?! \]\] | \s* </b> )
           . 
      )+?
 )
 \s* </b> \s* </br> \s* </br> \s* 
 (                                 # (2)
      (?:
           (?! \s* \]\] )
           . 
      )*
 )
 \s* 
 \]\]
 \s* 
 </description>

Upvotes: 1

Related Questions