Android Question Regex code higlighting

Fusseldieb

Active Member
Licensed User
Longtime User
Hello all,
I want to highlight tags from a code.
I have read that REGEX is better for that kind of use.
Now I wanted to highlight a commented code and I came up with the following REGEX: (').+\w.+
This REGEX I have made by myself on the website: http://www.regexr.com/
It highlights the entire comment, which is good, but when I put into B4A, it replaces it.
B4X:
Dim str As String = RegexReplace("(').+\w.+", WholeCode, "Testest")
EditText1.Text=str

Sub RegexReplace(Pattern As String, Text As String, Replacement As String) As String
  Dim m As Matcher
  m = Regex.Matcher2(Pattern, Regex.MULTILINE, Text)
  Dim jo As JavaObject = m
  Return jo.RunMethod("replaceAll", Array(Replacement))
End Sub
I wanted to insert a code BEFORE the match and AFTER the REGEX match.

Example:
I have:
B4X:
blablabla
'Hello World
blablabla
I want to make like this:
B4X:
blablabla
<insertstring>'Hello World<insertstring>
blablabla

I hope anyone has a solution for this problem.

Thanks in advance ;)
 
Top