By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,070 Members | 1,718 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,070 IT Pros & Developers. It's quick & easy.

Regular Expression

P: n/a
Can someone please show me how to create a regular expression to do the
following

My text is set to
[vbl] MyColumn{1, 100} Test

I want a regular expression that sets the text to the following
[vbl] testMyColumn{1, 100}Test

Basically I want the regular expression to add the word test infront of the
word MyColumn and also remove 4 spaces after } and the word Test.

Thanks
Nov 15 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
> My text is set to
[vbl] MyColumn{1, 100} Test

I want a regular expression that sets the text to the following
[vbl] testMyColumn{1, 100}Test


The pattern is:

string pattern = @"(\[vbl] )(MyColumn\{\d+, \d+\})(\s+)(Test)";

and you should use a MatchEvaluator that returns the propper string.

Hope that helps,
-JG
Nov 15 '05 #2

P: n/a

Hi Buddy,

I think you can do something like this:

string str="[vbl] MyColumn{1, 100} Test";
Regex rg1=new Regex("\\s{4}");
string [] collection=rg1.Split(str);
Regex rg2=new Regex("My");
string new1=rg2.Replace(collection[0],collection[1].ToLower());
string new2=new1+collection[1];
MessageBox.Show(new2);

Hope this helps,
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.

--------------------
| From: "Buddy" <Bu***@onlinehome.com>
| Subject: Regular Expression
| Date: Fri, 24 Oct 2003 23:18:50 +0100
| Lines: 15
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <uw*************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 81-1-69-6.homechoice.co.uk 81.1.69.6
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!tk2msftn gp13.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193940
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Can someone please show me how to create a regular expression to do the
| following
|
| My text is set to
| [vbl] MyColumn{1, 100} Test
|
| I want a regular expression that sets the text to the following
| [vbl] testMyColumn{1, 100}Test
|
| Basically I want the regular expression to add the word test infront of
the
| word MyColumn and also remove 4 spaces after } and the word Test.
|
| Thanks
|
|
|

Nov 15 '05 #3

P: n/a
Thanks for the reply Jeffrey, I only want to know what's
the Regular Expression parttern?

Thanks,
-----Original Message-----

Hi Buddy,

I think you can do something like this:

string str="[vbl] MyColumn{1, 100} Test";
Regex rg1=new Regex("\\s{4}");
string [] collection=rg1.Split(str);
Regex rg2=new Regex("My");
string new1=rg2.Replace(collection[0],collection [1].ToLower());string new2=new1+collection[1];
MessageBox.Show(new2);

Hope this helps,
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.
--------------------
| From: "Buddy" <Bu***@onlinehome.com>
| Subject: Regular Expression
| Date: Fri, 24 Oct 2003 23:18:50 +0100
| Lines: 15
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165| Message-ID: <uw*************@tk2msftngp13.phx.gbl>
| Newsgroups: microsoft.public.dotnet.languages.csharp
| NNTP-Posting-Host: 81-1-69-6.homechoice.co.uk 81.1.69.6
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl! tk2msftngp13.phx.gbl| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:193940| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Can someone please show me how to create a regular expression to do the| following
|
| My text is set to
| [vbl] MyColumn{1, 100} Test
|
| I want a regular expression that sets the text to the following| [vbl] testMyColumn{1, 100}Test
|
| Basically I want the regular expression to add the word test infront ofthe
| word MyColumn and also remove 4 spaces after } and the word Test.|
| Thanks
|
|
|

.

Nov 15 '05 #4

P: n/a

Hi Buddy,

Net Framework provides System.Text.RegularExpressions namespace for us to
work with Regular Expression.
You can get a simple general introduction of ".NET Framework Regular
Expressions" at the link below:
http://msdn.microsoft.com/library/de...us/cpguide/htm
l/cpconcomregularexpressions.asp

But if you want to get a detailed reference of it, you can refer to the
JScript .NET's "Regular Expression Syntax" section, link:
http://msdn.microsoft.com/library/de...us/jscript7/ht
ml/jsreconbackreferences.asp

Finally, there is a web site special for Regular Expression, you can get a
tutorial from it at:
http://www.regular-expressions.info/tutorial.html

If I misunderstand your meanning, please feel free to tell me.

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.

--------------------
| Content-Class: urn:content-classes:message
| From: "Bu***@Onlinehome.com" <an*******@discussions.microsoft.com>
| Sender: "Bu***@Onlinehome.com" <an*******@discussions.microsoft.com>
| References: <uw*************@tk2msftngp13.phx.gbl>
<sS*************@cpmsftngxa06.phx.gbl>
| Subject: RE: Regular Expression
| Date: Sat, 25 Oct 2003 05:30:30 -0700
| Lines: 70
| Message-ID: <02****************************@phx.gbl>
| MIME-Version: 1.0
| Content-Type: text/plain;
| charset="iso-8859-1"
| Content-Transfer-Encoding: 7bit
| X-Newsreader: Microsoft CDO for Windows 2000
| Thread-Index: AcOa88b1uu7kg/nXT9Oyh6bxrarHfQ==
| X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
| Newsgroups: microsoft.public.dotnet.languages.csharp
| Path: cpmsftngxa06.phx.gbl
| Xref: cpmsftngxa06.phx.gbl microsoft.public.dotnet.languages.csharp:194005
| NNTP-Posting-Host: TK2MSFTNGXA08 10.40.1.160
| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
|
| Thanks for the reply Jeffrey, I only want to know what's
| the Regular Expression parttern?
|
| Thanks,
|
| >-----Original Message-----
| >
| >Hi Buddy,
| >
| >I think you can do something like this:
| >
| >string str="[vbl] MyColumn{1, 100} Test";
| >Regex rg1=new Regex("\\s{4}");
| >string [] collection=rg1.Split(str);
| >Regex rg2=new Regex("My");
| >string new1=rg2.Replace(collection[0],collection
| [1].ToLower());
| >string new2=new1+collection[1];
| >MessageBox.Show(new2);
| >
| >Hope this helps,
| >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.
| >
| >--------------------
| >| From: "Buddy" <Bu***@onlinehome.com>
| >| Subject: Regular Expression
| >| Date: Fri, 24 Oct 2003 23:18:50 +0100
| >| Lines: 15
| >| X-Priority: 3
| >| X-MSMail-Priority: Normal
| >| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| >| X-MimeOLE: Produced By Microsoft MimeOLE
| V6.00.2800.1165
| >| Message-ID: <uw*************@tk2msftngp13.phx.gbl>
| >| Newsgroups: microsoft.public.dotnet.languages.csharp
| >| NNTP-Posting-Host: 81-1-69-6.homechoice.co.uk 81.1.69.6
| >| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!
| tk2msftngp13.phx.gbl
| >| Xref: cpmsftngxa06.phx.gbl
| microsoft.public.dotnet.languages.csharp:193940
| >| X-Tomcat-NG: microsoft.public.dotnet.languages.csharp
| >|
| >| Can someone please show me how to create a regular
| expression to do the
| >| following
| >|
| >| My text is set to
| >| [vbl] MyColumn{1, 100} Test
| >|
| >| I want a regular expression that sets the text to the
| following
| >| [vbl] testMyColumn{1, 100}Test
| >|
| >| Basically I want the regular expression to add the
| word test infront of
| >the
| >| word MyColumn and also remove 4 spaces after } and the
| word Test.
| >|
| >| Thanks
| >|
| >|
| >|
| >
| >.
| >
|

Nov 15 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.