| CodeGuru Home | VC++ / MFC / C++ | .NET / C# | Visual Basic | Newsletters | VB Forums | Developer.com |
|
|||||||
| Visual C++ Programming Ask questions about Windows programming with Visual C++ and help others by answering their questions. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
||||
|
||||
|
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);
}
Last edited by Igor Vartanov; November 11th, 2009 at 04:35 PM. |
|
#4
|
|||
|
|||
|
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.
|
|
#5
|
|||
|
|||
|
Re: Regular Expressions question
Yes, C++0x includes the <regex> header which is based on Boost.RegEx.
|
![]() |
| Bookmarks |
|
||||||
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|