Please spend a few minutes to go through the topic posted by GregBrannon above. Your original post is hard to read and understand.
It seems that you're looking for a way to extract JSP tags where the tags:
- can be on a single line or multiple lines
- may contain scriptlets
If your JSP files are written in
XML format, then you can use an XML parser to do the job. However from your example this does not seem to be the case.
You can try using
Jasper to get an object model from your JSP page. See
Hacking Jasper to Get Object Model of a JSP Page | Java Code Geeks.
You can certainly use
regex to do this, but be aware that it's an iterative process as regex is not easy to learn, and a single character mistake can cause the regex parser to fail for some or all cases.
If you want to go with the regex approach, the following should help you as a starting point:
Pattern tagPattern = Pattern.compile(".*?(<.+?[^%]>).*", Pattern.DOTALL);
It should work for the 2 cases in your post (based on my understanding, which may be wrong, hence the call for you to properly format and post your code). (Note the use of a capturing group in the regex.)
If you need to ask further questions on this, please post it in the following format:
Original string:
Paste your original string here
Extracted string:
Write the bit to be extracted from the original string here
You'd also want to write unit tests to test and regression-test if the above expression does not work for other cases that you may have in your JSP files. This is so that as you modify the regex, you don't accidentally cause it to fail for earlier cases that worked.
Further info on regex: