Android Question Regex in B4A 9.30

Discussion in 'Android Questions' started by peacemaker, Jul 25, 2019.

Tags:
  1. peacemaker

    peacemaker Well-Known Member Licensed User

    HI, All
    Before update to B4A 9.30 this sub worked OK:

    Code:
    Sub IfFormattedQR (text As StringAs Boolean
        
    Dim res As Boolean = Regex.IsMatch("\d{4,}", text)
        
    Return res
    End Sub
    Strings like "TEST0000", "TEST9999"... were matched OK, as on https://regex101.com

    After update to B4A v.9.30 ... it's a miracle - do not match anymore. :(
    Always at jdk-11.0.1.
    Am i ill ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    TEST0000 is not a match for \d{4,}.
    0000 is a match.

    You can change the pattern to \w*\d{4,} or use Regex.Matcher instead of Regex.IsMatch.
     
    peacemaker likes this.
  3. peacemaker

    peacemaker Well-Known Member Licensed User

    Thanks, Erel, but.... before at https://regex101.com and in code it was matched, i remember... o_O
    But "\w*\d{4,}\w*" works now, thanks.
     
  4. DonManfred

    DonManfred Expert Licensed User

    i tried it. With the defaults it does not match.
    If you change the site to use a matcher then it works.
     
    Last edited: Jul 26, 2019
  5. Erel

    Erel Administrator Staff Member Licensed User

    The code from the first post will not "work" (return true from TEST0000) with any version of B4A. You can try it.
    It cannot "work" because TEST0000 doesn't match the pattern.
     
    DonManfred likes this.
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice