Regular Expression help

  1. 3 months ago

    Arief S

    Dec 10 Bandung - Indonesia

    Hi,

    I have a data,
    AW0001
    AW0002
    BW0001
    BW0002
    AS0001
    BS0002

    I want to count every data based from first two letter code,

    rex.SearchPattern = "^.*\b(AW|BW|AS|BS)\b.*$"

    The code is worked if I do type the full code like,
    rex.SearchPattern = "^.*\b(AW0001|BWBW0001|ASAS0001|BSBS0002)\b.*$"

    is there any other ways to do this with regex ? I have used .left function but way to slow.

    thanks
    Regards,
    Arief

    Its solved,
    by change the option into Global, multiline and insensitive to checked value..

    https://regex101.com/r/CBXWMo/1

    thanks for all the helps.

    Regards,
    Arief

  2. Kem T

    Dec 10 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    The first pattern won't work because the space between a number and a letter is not considered a word break, so \b will not match there.

    I'm not sure if the items you're interested in start each line or can be mixed into text, but assuming the latter and the digits are important, this will do it:

    rex.SearchPattern = "\b([a-z]{2})(\d{4})"

    On every match, the first subexpression will be the letters and the second will be the digits.

  3. Edward P

    Dec 10 Pre-Release Testers Tampa, FL, USA

    Not to ever want to be one to contradict the master of RegEx, but shouldn't it be

    rex.SearchPattern = "\b([A-Z]{2})(\d{4})"

    since his example shows the two-letter codes in uppercase?

  4. Kem T

    Dec 10 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    That's fine too. By default, Xojo's PCRE implementation is case-insensitive. If that is changed in code through the RegEx.Options or the (?-i) switch, my way would stop working if the data is indeed as shown. From that perspective, your way is probably better.

    BTW, that's why RegExRX includes the switch when copying the pattern for use in Xojo or other languages, so there is no confusion.

  5. Edward P

    Dec 10 Pre-Release Testers Tampa, FL, USA

    Thanks for the explanation. I can't recall if I ever noticed that the implementation is case-insensitive unless explicitly changed.

  6. Jean-Yves P

    Dec 10 Pre-Release Testers, Xojo Pro Europe (France, Besançon)

    Kem, I'll love the day I will have enough money to go to XDC and meet you in person !

  7. Kem T

    Dec 10 Pre-Release Testers, Xojo Pro, XDC Speakers New York

    Yes, yes, everyone agrees, it's the highlight of XDC.

    :D

    (Seriously, I appreciate that.)

  8. Alberto D

    Dec 10 Pre-Release Testers, Xojo Pro

    @Jean-YvesPochez Kem, I'll love the day I will have enough money to go to XDC and meet you in person !

    +1

  9. I watch quietly from the sidelines but thanks to Kem I have become a user of regular expressions. It can be a whole lot easier than trying to program stuff. Thanks!

  10. Arief S

    Dec 10 Bandung - Indonesia

    Hi Mr. Tekinay,

    rex.SearchPattern = "\b([a-z]{2})(\d{4})"

    The code is working, its counting all the code read by letter from a-z.

    I want to categorized it into 4 options.

    rex.SearchPattern = "^.*\b(AW|BW|AS|BS)\b.*$"
    rex.SearchPattern = "^.*\b(AG|AE|AJ|BJ)\b.*$"
    rex.SearchPattern = "^.*\b(AB|BB|AM|MW)\b.*$"
    rex.SearchPattern = "^.*\b(AC|BC|AS|BS)\b.*$"

    thanks
    Regards,
    Arief

  11. Arief S

    Dec 10 Answer Bandung - Indonesia

    Its solved,
    by change the option into Global, multiline and insensitive to checked value..

    https://regex101.com/r/CBXWMo/1

    thanks for all the helps.

    Regards,
    Arief

or Sign Up to reply!