RxExp to match the first tag

I am trying to match text content with the first tag <test>.

For instance:

<test>SAMPLE TEXT</test><test>SAMPLE TEXT2</test><test>SAMPLE TEXT3</test>

If i use

("<test>(.*)</test>")`

I got it:

SAMPLE TEXT</test><test>SAMPLE TEXT2</test><test>SAMPLE TEXT3

How do I get only the contents of the first tag <test>: SAMPLE TEXT?

+3
source share
4 answers

(.*)is greedy (which means "everything you can find until you find the last one </test>"), you are looking for a non-greedy version (.*?)(which means "as little as possible, find the very first </test>").

Cthulu, HTML HTML .NET. , XML ( HTML), , , ( ) XmlReader.

+4

.* .*?

, . .

+1

@Radu , :

"<test>([^<]*)</test>"
+1

, XML, :

("<test>([^<]*)</test>")

will parse all characters other than '<', which is the first character you want to ignore.

NTN.

+1
source

All Articles