dcsimg
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Capturing Groups using Regex

  1. #1
    Join Date
    Jan 2019
    Posts
    1

    Capturing Groups using Regex

    I am trying to capture groups in JAVA using Pattern Matcher,

    This is how the data looks like, multiple code-value pairs, all are optional
    /BO1/AAAA/BO2/BBBB/BO3/CCCC/OB1/DDD/OB2/EEEE/OB3/FFFF
    /BO1/AAAA/BO3/CCCC/OB1/DDD/OB3/FFFF

    I have created a regex expression like this
    "(/BO1/[^\\n]*){0,1}(/BO2/[^\\n]*){0,1}(/BO3/[^\\n]*){0,1}(/OB1/[^\\n]*){0,1}(/OB2/[^\\n]*){0,1}(/OB3/[^\\n]*){0,1}"

    The groups are not being captured as it required as everything is captured in the first group
    This is the output string I am generating, concatenating all the groups with pipe delimited.

    |/BO1/AAAA/BO2/BBBB/BO3/CCCC/OB1/DDD/OB2/EEEE/OB3/FFFF|null|null|null|null|null
    |/BO1/AAAA/BO3/CCCC/OB1/DDD/OB3/FFFF|null|null|null|null|null

    Can someone please help to figure out the issue in the regex to capture into different groups...

  2. #2
    Arjay's Avatar
    Arjay is online now Moderator / MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    12,989

    Re: Capturing Groups using Regex

    Must you use RegEx? Could you use split string instead and read the result into string array where the even number indexes are the keys and the odd number indexes are the values?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width




On-Demand Webinars (sponsored)