Answer the question
In order to leave comments, you need to log in
How to get value from tag?
You need to get the value of the parameter from the tag.
For example:
<post id = x1>
//неизвестное кол-во записей (тегов и т.д.)
<put id=y2 max=MX1>
//неизвестное кол-во записей (тегов и т.д.)
</post>
<post id = x2>
//неизвестное кол-во записей (тегов и т.д.)
<put id=y2 max=MX2>
//неизвестное кол-во записей (тегов и т.д.)
</post>
Answer the question
In order to leave comments, you need to log in
Matching hierarchical structures with regexps is quite a chore, and not every regexp engine can recursively regexps. I assume that in your case these post tags are not nested.
the easiest way is to match in two steps: first, with the simplest regexp, pull out one block with the post, and then with the same primitive regexp in the pulled out part, find the first matching attribute.
compared to one tricky regexp that does everything at once, this will work faster, and much easier / clearer for those who have to maintain this code.
and if you still need exactly one regexp, then it can look something like this:
Of course, this is a simplified example, you will have to at least handle other tags and attributes, whitespaces and so on. but there is the place where the construction with the noncapturing group greedily matches where the point with the negative lookahead is probably what you asked about.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question