Tan Kucukhas
Tan Kucukhas

Reputation: 827

Regex between text with different characters on NotePad++

I am trying to catch the code starting with <div id="usermenu"> until the end of it's close tag </div> Can I do this with regex. See the code example

<div id="logo"> LOGO   <a href="index.html"></a></div>
    	    <!-- REGEX STARTS HERE -->
		<div id="usermenu">
 BLA BLA BLA BLA
.......................<br/>
          		<div class="another-div>LA BLA BLA BLA<div>
 BLA BLA BLA BLA
.......................<br/>
                 	<div class="some-another-div>LA BLA BLA BLA<div> 		
 BLA BLA BLA BLA
.......................<br/>
</div>

<!-- REGEX STOPS HERE -->
<div id="topmenu-position">TOP MENU</div>

Upvotes: 2

Views: 392

Answers (3)

Kennah
Kennah

Reputation: 487

This works.

<div id="usermenu">[^\<]{0,}</div>

If you want only that which is between the tags, say for a replace, use this.

<div id="usermenu">([^\<]{0,})</div>

Upvotes: 1

jbiz
jbiz

Reputation: 414

I don't have a copy of Notepad++ handy, but something like this might work:

(<div id="usermenu">.+?<\/div>)

Just make sure that you enable the dot (.) to match all newline characters. You can test it out here http://regex101.com/ with:

/(<div id="usermenu">.*?<\/div>)/s

FWIW, s = dot (.) matches everything including newline http://perldoc.perl.org/perlre.html#Modifiers. Just as an aside though, I would probably use an HTML parser to perform something like this. If you're into Python, BeautifulSoup is one such parser.

Upvotes: 0

hwnd
hwnd

Reputation: 70732

You can use the following regex in Notepad++.

Make sure "Regular expression" along with . matches newline is checked.

<div id="usermenu">.*?</div>

Upvotes: 2

Related Questions