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..
 

NJDude

Expert
Licensed User
Longtime User
Depends how are you reading that string, if you are doing it individually then you just do something like:
B4X:
MyString = "<!--Hello there-->"
MyString = MyString.Replace("<!--", "").Replace("-->", "")
 
Upvote 0

hillzx

Member
Licensed User
Longtime User
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

DonManfred

Expert
Licensed User
Longtime User
Try this example please...

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

Attachments

  • hillzx.zip
    6 KB · Views: 248
Last edited:
Upvote 0

DonManfred

Expert
Licensed User
Longtime User
Here is another version of it... This can find more than one in a complete source...
Have fun with it ;-)

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

results in

B4X:
try
to
find
more
 

Attachments

  • hillzxreloaded.zip
    6.3 KB · Views: 248
Upvote 0

edgeryder1000

Member
Licensed User
Longtime User
This might work

B4X:
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
Top