Regex question

  • Thread starter Thread starter Tamir Khason
  • Start date Start date
T

Tamir Khason

How can I perform such thing using Regex?
I need to catch numbers comes after "Word1" or "Word2"
Something like this:
Word1|Word2(?<TEST>\d)

Strings:
wrtsdlfgkjsdlkfgWord1332233sdfglkjdslkfgjsldkgjWord22344sdfoisdfkjgh
This should catch : TEST:221122,TEST2344
PLZ help
 
try this

(Word1|Word2)(? said:
wrtsdlfgkjsdlkfgWord1332233sdfglkjdslkfgjsldkgjWord22344sdfoisdfkjgh

if u examime groups["TEST"]
the result should be 332233 and 2344

hope that helps

Du
 
Hi Tamir,

Based on my understanding, you want to use Regular Expression in .Net to do
some string match.

For your sample, I have writen code for you. Please do like this:

private void button_Click(object sender, System.EventArgs e)
{
string
inputstring="wrtsdlfgkjsdlkfgWord1332233sdfglkjdslkfgjsldkgjWord22344sdfoisd
fkjgh";
Regex rg=new Regex(@"(Word1|Word2)(?<TEST>\d+)");
MatchCollection mc=rg.Matches(inputstring);
for(int i=1;i< mc.Count+1;i ++)
{
MessageBox.Show("The "+ i.ToString() +"th match TEST is: "
+mc[i-1].Groups["TEST"].Value);
}
}

Note: Du Dang's suggestion has a little problem, you should place
Word1|Word2 together, or Word2 will go together with "(?<TEST>\d+)"

=========================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

Does my reply make sense to you? Is your problem resolved?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

Can not you see my reply ? I can find my reply in google, please refer to:
http://groups.google.com/groups?q="Regex+question"+"Jeffrey+Tan"&hl=
zh-CN&lr=&ie=UTF-8&oe=UTF-8&selm=6Iw73AYDEHA.1672%40cpmsftngxa06.phx.gbl&rnu
m=1

Also, I have included my original reply in this post:

"Based on my understanding, you want to use Regular Expression in .Net to
do
some string match.

For your sample, I have writen code for you. Please do like this:

private void button_Click(object sender, System.EventArgs e)
{
string
inputstring="wrtsdlfgkjsdlkfgWord1332233sdfglkjdslkfgjsldkgjWord22344sdfoisd
fkjgh";
Regex rg=new Regex(@"(Word1|Word2)(?<TEST>\d+)");
MatchCollection mc=rg.Matches(inputstring);
for(int i=1;i< mc.Count+1;i ++)
{
MessageBox.Show("The "+ i.ToString() +"th match TEST is: "
+mc[i-1].Groups["TEST"].Value);
}
}

Note: Du Dang's suggestion has a little problem, you should place
Word1|Word2 together, or Word2 will go together with "(?<TEST>\d+)"

=========================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance."

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
Hi Tamir,

Have recieved my reply ? Does it work for you?

Please feel free to feedback. Thanks

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.
 
thank you fore response. I did not recieve your previoue reply, but already
solved it.
tnx
 
Back
Top