Regex to match html tag opening and closing tag and everthing between the tags (please check the image)
Clash Royale CLAN TAG#URR8PPP
Regex to match html tag opening and closing tag and everthing between the tags (please check the image)
I want to match this kind of pattern and everything between the tags.
I have tried everything I need the solution for this particular problem.
– Alifa
Aug 10 at 4:41
Generally, we prefer you to post code (even example code) as text, not as a picture. Could you paste the original code (ensuring every line has a 4 space indent) to replace the picture?
– Graham
Aug 10 at 4:52
1 Answer
1
If you want a quick, usable, but (inevitably) imperfect solution, you can use <li[^>]*>.*?</li>
. The ideal use case is low-use find-and-replace in a text file, not as any part of an actual HTML parser.
<li[^>]*>.*?</li>
Also, you'll need to have singleline mode (sometimes called dot-all mode) enabled.
Edit:
I really don't know what's up with Python and newlines, but I was able to get this working:
re.sub(r'<li[^>]*>(?:.|n)*?</li>', '', instr)
To generalize to any number (if Python >= 3.6):
n = 8726872
re.sub(fr'<li id="n"[^>]*>(?:.|n)*?</li>', '', instr)
And obligatory parsing HTML the better (safer and cleaner way) link:
Parsing HTML using Python
Unfortunaterly Its not working !
– Alifa
Aug 10 at 4:47
Oh sorry, I made a fatal error and eschewed my usual practice of verifying my answers. Apologies, I've fixed it.
– Graham
Aug 10 at 4:57
It is matching only 1 out of 75 patterns, I have added the exact code please try to accomodate the number matching pattern as well with opening line tag. Please check this url for code pastebin.com/bY52ua07
– Alifa
Aug 10 at 5:02
Try checking the box labelled
. matches newline
. I think that will solve your problem.– Graham
Aug 10 at 5:07
. matches newline
If the id is important it can just be modified to:
<li id="8726872"[^>]*>.*?</li>
– Graham
Aug 10 at 5:10
<li id="8726872"[^>]*>.*?</li>
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
In case you are attempting to process XMl or HTML via regexes please compare stackoverflow.com/a/1732454/7733418
– Yunnosch
Aug 10 at 4:34