CodeGuru Forums -
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic Newsletters VB Forums Developer.com


Newest CodeGuru.com Articles:

  • Deploying Windows Server 2008 with System Center
  • Remote Desktop Protocol Performance Improvements in Windows Server 2008 R2 and Windows 7
  • The Microsoft Dynamics CRM Security Model
  • SQL Server Modeling Services with Microsoft Visual Studio 2010 Beta 2

  • Search CodeGuru:
     



    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming
    FAQ Members List Calendar Search Today's Posts Mark Forums Read

    Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions.

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1    
    Old November 11th, 2009, 01:36 AM
    Shvalb Shvalb is offline
    Member
     
    Join Date: Dec 2004
    Posts: 282
    Shvalb is an unknown quantity at this point (<10)
    Question Regular Expressions question

    Hi,

    I have an expression that looks like this:

    @string1@\@string2@

    and my question is:

    How can I extract string1 and string 2 out of the expression using regular expression pattern ??

    I tried using the pattern: @.*.@
    but I think it's not good enough.

    Thanks.
    Reply With Quote
      #2    
    Old November 11th, 2009, 09:36 AM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,476
    hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+)
    Re: Regular Expressions question

    I don't think I'd bother with regex for such a simple parsing. Just split the string at the "/" then trim the "@" from each end.
    Reply With Quote
      #3    
    Old November 11th, 2009, 04:30 PM
    Igor Vartanov's Avatar
    Igor Vartanov Igor Vartanov is offline
    Elite Member
     
    Join Date: Nov 2000
    Location: Voronezh, Russia
    Posts: 3,194
    Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+) Igor Vartanov has a brilliant future (2000+)
    Re: Regular Expressions question

    Come on, hoxsiew, what are simple cases for but catching up a concept?


    Code:
    // 25.js
    main();
    
    function main()
    {
    	var re  = /@([^@]*)@[\\]*/g;  // the highlighted part is optional
    	var src = "@string 1@\\@string 2@\\@string 3@";
    	var arr = null;
    	var out = '';
    	var idx = 0;
    	while ((arr = re.exec(src)) != null)
    	{
    		if (out.length)
    			out += "\n";
    		out += '[' + (idx++) + '] ' + arr[1];
    	}
    	WScript.Echo(out);
    }
    __________________
    Respectfully,
    Igor

    Last edited by Igor Vartanov; November 11th, 2009 at 04:35 PM.
    Reply With Quote
      #4    
    Old November 11th, 2009, 04:43 PM
    hoxsiew hoxsiew is offline
    Senior Member
     
    Join Date: Feb 2005
    Posts: 1,476
    hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+) hoxsiew is a glorious beacon of light (400+)
    Re: Regular Expressions question

    Honestly, I've never used a regex in C/C++ (I'm not even sure how, is it in the standard now?); in perl however, they're practically mandatory, but I've not used perl since 1996.
    Reply With Quote
      #5    
    Old November 11th, 2009, 05:47 PM
    Lindley Lindley is offline
    Elite Member
    Power Poster
     
    Join Date: Oct 2007
    Location: Fairfax, VA
    Posts: 6,905
    Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+) Lindley is a name known to all (1000+)
    Re: Regular Expressions question

    Quote:
    Originally Posted by hoxsiew View Post
    Honestly, I've never used a regex in C/C++ (I'm not even sure how, is it in the standard now?)
    Yes, C++0x includes the <regex> header which is based on Boost.RegEx.
    Reply With Quote
    Reply

    Bookmarks
    Go Back   CodeGuru Forums > Visual C++ & C++ Programming > Visual C++ Programming


    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is On
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 03:16 PM.



    Acceptable Use Policy


    The Network for Technology Professionals

    Search:

    About Internet.com

    Legal Notices, Licensing, Permissions, Privacy Policy.
    Advertise | Newsletters | E-mail Offers


    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.