#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2018
    Posts
    3
    Rep Power
    0

    RegEx Help With Multiple Grouping


    I am trying to create a RegEx query for C# that will return all the matches found within quotes. I would like to have it setup in groups so I could specify the group being called in code but not required as I could also use something like RegEx.Matches(String, String) function as shown here.

    The issue I ran into with using C# Matches is that the below returns 48 matches so there must be some improvements that can be done to the RegEx query.
    Code:
    string pattern = "([^\"]*)"; // "([^"]*)"
    MatchCollection matches = Regex.Matches(ViewBag.user, pattern);
    RegEx Command w/ Groups
    (?<Username>"(["]*)"?)?(?<Verified>"([^"]*)")

    RegEx Command matching just a single quoted word
    "([^"]*)"

    RegEx String To Test On
    Code:
    "username": "BillyBob", "verified": true, "mfa_enabled": false, "id": "789632456119475101", "avatar": "8520bdedf1512343783ae5d12a120b1e", "discriminator": "1234", "email": "example@domain.com"
  2. #2
  3. Impoverished Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,796
    Rep Power
    9646
    I'm troubled by the fact that you're using regular expressions on a JSON string...

    If you want everything in quotes then you have to include quotes in the regex. Somehow. Like with assertions.
    Code:
    (?<=")([^"]+)(?=")

IMN logo majestic logo threadwatch logo seochat tools logo