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

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0

    Trying to match this...


    First, I have to admit I don't do a lot with regular expressions but I do recognize when I need them To that end I want to be able to search a text string and find all occurrences of "@[User::XXXXXX]" where XXX could be a mixture of alpha characters, numerics and punctuation. I can't for the life of my come up with the proper regular expression to search for that. I was hoping someone could lend me a hand...thanks!
  2. #2
  3. Forgotten Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    16,174
    Rep Power
    9644
    What have you tried so far, and what regex engine (or programming language) are you working with?
  4. #3
  5. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,470
    Rep Power
    1875
    Are you using grep / awk / perl / something else?
    Is there at most one per line, or more than one?
    Having found them, what do you want to do next?
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2012
    Posts
    6
    Rep Power
    0
    Originally Posted by requinix
    What have you tried so far, and what regex engine (or programming language) are you working with?
    I'm using c#. Ultimately I'd like to be able to iterate through the matches and only get back the XXX part. I haven't really tried anything due to my pathetic understanding of regular expression building

    Essentially I'm reading in a text file and searching for that pattern. Can do it other ways but seemed like a good fit for a regular expression.

    Thanx!
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,470
    Rep Power
    1875
    This -> https://msdn.microsoft.com/en-us/lib...v=vs.110).aspx

    Plus this (red text is output)
    Code:
    $ perl -n -e 'print "$1\n" if ( /@\[User::([^]]+)\]/ );'
    occurrences of "@[User::XXXXXX]" where XXX could be a mixture of alpha characters
    XXXXXX
    [User::XXXXXX]" where XXX c
    occurrences of "@[User::
    Where
    [^]]+ is a sequence of 1 or more characters of anything except a ],
    and placing that inside () means the sub-string will be captured into a capture variable of some sort ($1 in perl).

    The rest of the characters stand for themselves to establish the unique context where the useful information resides.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper

IMN logo majestic logo threadwatch logo seochat tools logo