Regex - words extraction

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
Saso said:
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)
 
Saso,

Here's your RegEx:

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

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


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


Ben Voigt said:
Saso said:
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
 
Ssamuel, I tryed your regex, but it seems that nothing happens,
MatchCollection is empy, Groups count is one.

Any suggestion?

Regards

ssamuel said:
Saso,

Here's your RegEx:

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

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


Stephan


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
 
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.

Any suggestion?

Regards

ssamuel said:
Saso,

Here's your RegEx:

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

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


Stephan


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
 
Ssamule, I just solved the problem, I mixed up the parameters of Regex.Match
method :). It happens.

Thank you.
Saso

ssamuel said:
Saso,

Here's your RegEx:

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

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


Stephan


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
 
Saso said:
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);

}

Ben Voigt said:
Saso said:
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
 
Back
Top