Monday 9 September 2019

java - RegEx for matching between any two HTML tags



I have the following content :





I am trying to match the TEST-TEXT string to replace it is value but only when it is a text and not within an attribute value.



I have checked the concepts of look-ahead and look-behind in Regex but the current issue with that is that it needs to use a fixed width for the match here is a link regex-match-all-characters-between-two-html-tags that show case a very similar case but with an exception that there is a span with a class to create a match
also checked the link regex-match-attribute-in-a-html-code



here are two regular expressions I am trying with :






  1. \"([^"]*)\"

  2. (?s)(?<=<([^{]*)>)(.+?)(?=)




both are not working for me try using [https://regex101.com/r/ApbUEW/2]



I expect it to match only the string when it is a text
current behavior it matches both cases




Edit : I want the text to be dynamic and not specific to TEST-TEXT


Answer



A RegEx for that a string between any two HTML tags



(?![^<>]*>)(TEST\-TEXT)


No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...