ASK how to get a string between <!-- and --> ?

hillzx

Member
Licensed User
Longtime User
Hey guys, i really need your help, i have no idea about regex, how to get a string between <!-- and --> ?

For example :

Task:
<!--Hello there-->
<!--This is a test string-->

Result:
Hello there
This is a test string

Thank you for your help..
 
Thanks for your reply, but i have a little problem, in my case, i have to catch only string <!-- --> inside a whole source code of webpage and ignore another character outside of <!-- and -->

do you have another solution sir ? :)
 
Upvote 0
Try this example please...

PS: I´m a b4a-beginner so please exuse if there is an better solution for this :D
 

Attachments

Last edited:
Upvote 0
Here is another version of it... This can find more than one in a complete source...
Have fun with it ;-)

Code: Copy
search = "some useless other text... <!-- try --> some useless other text... <!-- to --> some useless other text... <!-- find --> some useless other text... <!-- more... -->"

results in

Code: Copy
try
to
find
more
 

Attachments

Upvote 0
This might work

Code: Copy
Dim result(99) As String
Dim answer As List
answer.Initialize
Dim M As Matcher
M = Regex.Matcher("(<!--).*(-->)",String1) 'String1 is the text you are searching
Do While M.Find
    i = i + 1
    result(i) = M.Match.Replace("<!--", "").Replace("-->", "")
    answer.Add(result(i))
Loop
 
Last edited:
Upvote 0
Back
Top