Sublime Forum

Regex: Select only the first instance of search results / first match

#1

hello, I have many of this

tags on a html page. I want to select with regex only this first instance of tags. I made a regex, but this formula selects both . tags. I want only the first one.

FIND: \b<tr>[\s\S]+</tr>\b

<tr>
<td class="right">On December 15, 2012, in <a href="https://mywebsite.com/index.html" title="See all articles here" class="external" rel="category tag">Expert-Expert</a>, by Michael Ende</td>
</tr>

and more

<tr>
Other Code
</tr>

0 Likes

#2

Select and replace the first instance:

SEARCH: (?s)\A.*?<tr>\s*\K.*?(\s*</tr>)(?=$)
REPLACE BY: NEW CONTENT $1

or

SEARCH: (?s)\A.*?<tr>\s*\K.*?(\s*</tr>)
REPLACE BY: NEW CONTENT $1

Select and replace the last instance:

SEARCH: (?s)<tr>.*</tr>.*?<tr>\K.+?(?=</tr>.*?\z)
REPLACE BY: \r NEW CONTENS $1 \r

or

SEARCH: (?s)\A.*<tr>\K.+?(?=</tr>)
REPLACE BY: \r NEW CONTENS $1 \r

Source: https://community.notepad-plus-plus.org/topic/12353/regex-select-only-the-first-instance-of-search-results-first-match

0 Likes