Home All Groups Group Topic Archive Search About

Regex - words extraction

Author
26 Oct 2006 1:50 PM
Saso
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

Author
26 Oct 2006 1:59 PM
Ben Voigt
"Saso" <S***@discussions.microsoft.com> wrote in message
news:4D993A15-C126-45D5-8130-53DC9B4CCFBC@microsoft.com...
> 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)

Show quote
>
> Regards
> Saso
Author
26 Oct 2006 2:16 PM
Saso
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);
            }


Show quote
"Ben Voigt" wrote:

>
> "Saso" <S***@discussions.microsoft.com> wrote in message
> news:4D993A15-C126-45D5-8130-53DC9B4CCFBC@microsoft.com...
> > 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
>
>
>
Author
27 Oct 2006 3:13 PM
Ben Voigt
"Saso" <S***@discussions.microsoft.com> wrote in message
news:9F6258F7-1C31-43AA-BC96-6DE828CED1D0@microsoft.com...
> 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);
>            }

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);

}


Show quote
>
>
> "Ben Voigt" wrote:
>
>>
>> "Saso" <S***@discussions.microsoft.com> wrote in message
>> news:4D993A15-C126-45D5-8130-53DC9B4CCFBC@microsoft.com...
>> > 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
>>
>>
>>
Author
26 Oct 2006 2:10 PM
ssamuel
Saso,

Here's your RegEx:

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

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


Stephan



Saso wrote:
Show quote
> 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
Author
26 Oct 2006 5:03 PM
Saso
Ssamuel, I tryed your regex, but it seems that nothing happens,
MatchCollection is empy, Groups count is one.

Any suggestion?

Regards

Show quote
"ssamuel" wrote:

> Saso,
>
> Here's your RegEx:
>
> \<(.*)\:\:(.*)\[(.*)\]\>
>
> Download a product called The Regulator. It'll come up in Google.
>
>
> Stephan
>
>
>
> Saso wrote:
> > 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
>
>
Author
26 Oct 2006 5:21 PM
ssamuel
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



Saso wrote:
Show quote
> Ssamuel, I tryed your regex, but it seems that nothing happens,
> MatchCollection is empy, Groups count is one.
>
> Any suggestion?
>
> Regards
>
> "ssamuel" wrote:
>
> > Saso,
> >
> > Here's your RegEx:
> >
> > \<(.*)\:\:(.*)\[(.*)\]\>
> >
> > Download a product called The Regulator. It'll come up in Google.
> >
> >
> > Stephan
> >
> >
> >
> > Saso wrote:
> > > 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
> >
> >
Author
26 Oct 2006 5:30 PM
Saso
Ssamule, I just solved the problem, I mixed up the parameters of Regex.Match
method :). It happens.

Thank you.
Saso

Show quote
"ssamuel" wrote:

> Saso,
>
> Here's your RegEx:
>
> \<(.*)\:\:(.*)\[(.*)\]\>
>
> Download a product called The Regulator. It'll come up in Google.
>
>
> Stephan
>
>
>
> Saso wrote:
> > 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
>
>

AddThis Social Bookmark Button