CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2016
    Posts
    1

    Extract contents from a string using RegEX

    Hello.
    I have a big string , with this line specifically:
    /CIP3AdmSeparationNames [(Cyan)(Magenta)(Yellow)(Black)(PANTONE 647 C)] def

    I'm trying to extract ONLY the contents between Parentheses from that string with regex - but not being able to, tried a lot of combinations but none of 'em worked.

    Tried using this:
    Regex regex5 = new regex ("CIP3AdmSeparationNames [[]\(([^)]*)\)")
    But no matches have been found.

    The string has many lines - i just need this content. I don't wanna use .Indexof or .Substring - they were giving me bugs all the time.

    Thanks in advance for any help !
    Using latest Visual Studio and .NET

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Extract contents from a string using RegEX

    Have you tried any of the online regex testers? Search bing or google for "online regex tester"

  3. #3
    Join Date
    Jul 2001
    Location
    Sunny South Africa
    Posts
    11,283

    Re: Extract contents from a string using RegEX

    You say you do not want to use Substring and IndexOf because they were giving you bugs all the time, but want to dive in with Regex ( which is much more complicated and, IMHO unnecessary ) ? That is like swimming in the ocean eventhough you only have swimming floaties..
    Sorry for sounding crass, but I would suggest figuring out the Substring and IndexOf functions first. Strangely enough, these two functions are actually all you need. OK, perhaps a little bit more, but the need for RegEx is simply redundant.

    Have a look here: https://msdn.microsoft.com/en-us/lib...or=-2147217396

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured