Regular Expressions

  • Thread starter Thread starter VAADADMIN
  • Start date Start date
V

VAADADMIN

Looking for a little help. I cannot quite seem to get it right.

Here is the string:

addgroup ASOGRP supgroup(DUMMY0) owner(DUMMY0) data('AUTO SYSTEMS')

Result:

I want to pull out the string owner(DUMMY0) by itself. As my code is
written below, I get the remainder of the string as well. I guess I
need to get the substring of the string.

In the substring owner(DUMMY0), owner will always be there, but the
value in the () will be different. I want to pull the whole string
then I will pull out the value of owner.

I would appreciate any help you could give.

Code:

StreamReader sr1 = new StreamReader(args1);
int FindOccurrence = 1;

while ((sLine1 = sr1.ReadLine()) != null)
{
//string owner = @"(.\b(owner)\b.*)";
string owner = @"owner(\W.*\W)";
MatchCollection Listmatched = Regex.Matches(sLine1,
owner);
string owner1 =
Listmatched[FindOccurrence-1].Value.ToString();

Console.WriteLine(owner1);
}


Thanks
 
VAADADMIN said:
Looking for a little help. I cannot quite seem to get it right.

Here is the string:

addgroup ASOGRP supgroup(DUMMY0) owner(DUMMY0) data('AUTO SYSTEMS')

Result:

I want to pull out the string owner(DUMMY0) by itself. As my code is
written below, I get the remainder of the string as well. I guess I
need to get the substring of the string.

In the substring owner(DUMMY0), owner will always be there, but the
value in the () will be different. I want to pull the whole string
then I will pull out the value of owner.

I would appreciate any help you could give.

Code:

StreamReader sr1 = new StreamReader(args1);
int FindOccurrence = 1;

while ((sLine1 = sr1.ReadLine()) != null)
{
//string owner = @"(.\b(owner)\b.*)";
string owner = @"owner(\W.*\W)";
MatchCollection Listmatched = Regex.Matches(sLine1,
owner);
string owner1 =
Listmatched[FindOccurrence-1].Value.ToString();

Console.WriteLine(owner1);
}


Thanks


You are getting everything up to the last parenthesis. Put a ? after .*
to make it non-greedy.
 
Thank you very much, worked great.




VAADADMIN said:
Looking for a little help. I cannot quite seem to get it right.
Here is the string:
addgroup ASOGRP supgroup(DUMMY0) owner(DUMMY0) data('AUTO SYSTEMS')

I want to pull out the string owner(DUMMY0) by itself. As my code is
written below, I get the remainder of the string as well. I guess I
need to get the substring of the string.
In the substring owner(DUMMY0), owner will always be there, but the
value in the () will be different. I want to pull the whole string
then I will pull out the value of owner.
I would appreciate any help you could give.

StreamReader sr1 = new StreamReader(args1);
int FindOccurrence = 1;

while ((sLine1 = sr1.ReadLine()) != null)
{
//string owner = @"(.\b(owner)\b.*)";
string owner = @"owner(\W.*\W)";
MatchCollection Listmatched = Regex.Matches(sLine1,
owner);
string owner1 =
Listmatched[FindOccurrence-1].Value.ToString();
Console.WriteLine(owner1);
}

Thanks

You are getting everything up to the last parenthesis. Put a ? after .*
to make it non-greedy.

--
Göran Andersson
_____http://www.guffa.com- Hide quoted text -

- Show quoted text -
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top