B4J Question Get value of a meta data using regex

FrostCodes

Active Member
Licensed User
Longtime User
Please how can i parse meta data like link, license name short etc if the input data is exactly like this using regex(please the single quote and @ is included)

B4X:
    '@Link: http://test.com/hello/mylib
    '@license name short: DBAD
    '@license link: http://dbad.com

i tried this code

B4X:
'Allows parsing header like:     '@link: http://punchlinetech.com
Private Sub ParseProjectDocAttributes(Attribute As String) As String
   
    Dim HeaderMatcher As Matcher
    Dim HeaderMatcherData As String
   
    HeaderMatcher = Regex.Matcher("(?i)(?:'@" & Attribute & ")(?-i):(?:.*)", ProjectFileTextData)
   
    If HeaderMatcher.Find Then
       
        HeaderMatcherData =  HeaderMatcher.Match
       
        HeaderMatcherData = HeaderMatcherData.SubString(HeaderMatcherData.IndexOf(":") + 1)
        HeaderMatcherData = HeaderMatcherData.Trim
       
    End If
       
    Return HeaderMatcherData
 
End Sub


but its not working properly i think my regex is wrong. Any suggestions?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
B4X:
Dim s As String = "   '@Link: http://test.com/hello/mylib"
Dim rb As RegexBuilder
rb.Initialize.AppendAnyBut(Array("'")).AppendZeroOrMore.Append("'")
rb.StartCapture.AppendAnyBut(Array(":")).AppendAtLeastOne.EndCapture
rb.Append(":").Append(rb.CharWhitespace).AppendZeroOrMore
rb.StartCapture.Append(rb.CharAny).AppendAtLeastOne.EndCapture
Dim m As Matcher = Regex.Matcher(rb.Pattern, s)
If m.Find Then
   Log(m.Group(1))
   Log(m.Group(2))
End If
 
Upvote 0
Top