Answer the question
In order to leave comments, you need to log in
How to write a regular expression for a string in which the first part of the string is known, but the rest is unknown?
Follow the link to
regex101.com for test data. I need to pull out the contents of tags that contain a certain number <tr>
inside . <td class="num">1</td>
By reference - this is 1.
I understand how easy it is to find the right td - this is also done by reference. The problem for me is to throw in the regular expression all the rest of the contents of the tr tag. What is the best way to do this? Really it is necessary to register a template for each following line? Plus, I don’t quite understand what to do if the source code is without tabs: if you remove the tabs in the source code, then the regular expression stops working
Answer the question
In order to leave comments, you need to log in
<td class="num">(.*?)<\/td>
https://regex101.com/r/a1ygUX/1
It's worth noting that parsing html with regular expressions is a rather dumb task. On simple examples, it seems to work, but there is a rather big risk that everything will fall apart at any moment. Well, for example, one more class or attribute will be added to this num.
And regex parsing just can't be made reliable, because HTML is context-free, not a regular language.
https://stackoverflow.com/a/1732454
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question