Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / October 2006

Tip: Looking for answers? Try searching our database.

Regex - words extraction

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Saso - 26 Oct 2006 14:50 GMT
Hello!

I have the following string: <wordX::wordY[wordZ]>

I would like to extract from that string three words
wordX, wordY and wordZ by Regex usage.

Regards
Saso
Ben Voigt - 26 Oct 2006 14:59 GMT
> Hello!
>
> I have the following string: <wordX::wordY[wordZ]>
>
> I would like to extract from that string three words
> wordX, wordY and wordZ by Regex usage.

more or less:

r = new Regex(@"\<[^:]+::[^[]+\[[^\]]+\]\>");
matches = r.Match(str);
matches.Group(1)
matches.Group(2)
matches.Group(3)

> Regards
> Saso
Saso - 26 Oct 2006 15:16 GMT
Can you put exact code in written in c#. I tryed as follows, but nothing
happens.

           Regex r = new Regex(@"\<[^:]+::[^[]+\[[^\]]+\]\>");
           
           MatchCollection matches = r.Matches("<wordx::wordy[wordz]>");
           foreach (Match s in matches)
           {
               Console.WriteLine(s.Value);
           }

> > Hello!
> >
[quoted text clipped - 13 lines]
> > Regards
> > Saso
Ben Voigt - 27 Oct 2006 16:13 GMT
> Can you put exact code in written in c#. I tryed as follows, but nothing
> happens.
[quoted text clipped - 6 lines]
>                Console.WriteLine(s.Value);
>            }

Forgot the captures.  Here's the code:

Regex r = new Regex(@"^\<([^:]+)::([^[]+)\[([^\]]+)\]\>$");

Match m = r.Match("<wordx::wordy[wordz]>");

System.Diagnostics.Debug.WriteLine(m.Success);

foreach (Group s in m.Groups)

{

System.Diagnostics.Debug.WriteLine(s.Value);

}

>> > Hello!
>> >
[quoted text clipped - 13 lines]
>> > Regards
>> > Saso
ssamuel - 26 Oct 2006 15:10 GMT
Saso,

Here's your RegEx:

\<(.*)\:\:(.*)\[(.*)\]\>

Download a product called The Regulator. It'll come up in Google.

Stephan

> Hello!
>
[quoted text clipped - 5 lines]
> Regards
> Saso
Saso - 26 Oct 2006 18:03 GMT
Ssamuel, I tryed your regex, but it seems that nothing happens,
MatchCollection is empy, Groups count is one.

Any suggestion?

Regards

> Saso,
>
[quoted text clipped - 15 lines]
> > Regards
> > Saso
ssamuel - 26 Oct 2006 18:21 GMT
Saso,

The Match interface is obfuscated. Try:

 Regex re = new Regex(@"\<(.*)\:\:(.*)\[(.*)\]\>");
 string[] list = re.Split("<wordX::wordY[wordZ]>");

The first match is nothing, but 2, 3, and 4 (index 1, 2, and 3) are
your results.

Stephan

> Ssamuel, I tryed your regex, but it seems that nothing happens,
> MatchCollection is empy, Groups count is one.
[quoted text clipped - 22 lines]
> > > Regards
> > > Saso
Saso - 26 Oct 2006 18:30 GMT
Ssamule, I just solved the problem, I mixed up the parameters of Regex.Match
method :). It happens.

Thank you.
Saso

> Saso,
>
[quoted text clipped - 15 lines]
> > Regards
> > Saso

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.