473,507 Members | 6,295 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to math string containing '+,()' in .net

Hi all,

I want to apply regular expresion on string containing chatacters like
'(,')',+' and many such which we are using while creating pattern for
regulat expression.

But when i am applying regular expression on input string containing
abov character exception is getting raised.

Can some one tell me why this is happening and how to overcome this
problem.

Please help me.

thanks in advance.

Jun 30 '06 #1
5 1485
In order to represent normal characters, all of the following must be
escaped by a leading "\", e.g. the *character* "+" is "\+" in RegEx lingo;
otherwise, they represent the RegEx token, so "+" means "One or more
matches", etc

.. ? / \ [ ] { } ( ) + * |

Marc
Jun 30 '06 #2
ops

"archana" <tr**************@yahoo.com> wrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...
Hi all,

I want to apply regular expresion on string containing chatacters like
'(,')',+'


these are characters which have special meaning in regular expresions.
use \ before: \( \) \+

Jun 30 '06 #3
Oh - and for that reason it is often very convenient to use @"somestring"
notation in C# - so you can say:

new Regex(@"a\+b"); // means match the string "a+b"

which thanks to C# string-escaping is identical to:

new Regex("a\\+b");

The second one could be mis-read by somebody in a hurry as:

match a followed by one or more slashes followed by a b, e.g. the strings
@"a\b", @"a\\\b" etc

Regardles of whether you prefer using the C# @"" or "" syntax for RegEx, I
recommend you choose one and stick to it religiously for all RegEx in any
project; alternatively (better), put the patterns into a separate resource
file so that when editing them you only need to think about RegEx escaping,
and not C# escaping as well.

Marc


Jun 30 '06 #4
Hi,
thanks for your reply.

can you tell me one more thing?

What is difference in using () and [] in pattern.
Means what if i specify (ab) and [ab]. what is matching criteria then?

Thanks.

Marc Gravell wrote:
Oh - and for that reason it is often very convenient to use @"somestring"
notation in C# - so you can say:

new Regex(@"a\+b"); // means match the string "a+b"

which thanks to C# string-escaping is identical to:

new Regex("a\\+b");

The second one could be mis-read by somebody in a hurry as:

match a followed by one or more slashes followed by a b, e.g. the strings
@"a\b", @"a\\\b" etc

Regardles of whether you prefer using the C# @"" or "" syntax for RegEx, I
recommend you choose one and stick to it religiously for all RegEx in any
project; alternatively (better), put the patterns into a separate resource
file so that when editing them you only need to think about RegEx escaping,
and not C# escaping as well.

Marc
Jul 4 '06 #5
[ab] means "match a or b"
(ab) meeans "match the string ab, as a block usable for replace", e.g.

(note that pretty-much any valid regex expression can be used as a block
between the round brackets)

Debug.WriteLine(new Regex("(a)(bc)(d)").Replace("tahshabcdasd", "$1QQQ$3"));

will output "tahshaQQQdasd", because we have replaced the found expression
with the values of the first block ("a"), a literal "QQQ", and the third
block ("d")

Does that make sense?

Marc
Jul 4 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2282
by: Jussi Mononen | last post by:
Hi, I'm having problems to successfully execute the test scripts on a Compaq host ( OSF1 tr51bdev V5.1 2650 alpha ). Almost all tests end up with the following error message "PARI: *** ...
19
2017
by: Allen Thompson | last post by:
sorry for the simple question, haven't done this in a while. when I use the following script it keeps displaying the value of "x" like a string. for example, if I type the number 7 in the prompt,...
17
3589
by: cwdjrxyz | last post by:
Javascript has a very small math function list. However there is no reason that this list can not be extended greatly. Speed is not an issue, unless you nest complicated calculations several levels...
6
8754
by: RobG | last post by:
I am writing a script to move an absolutely positioned element on a page by a factor using style.top & style.left. The amount to move by is always some fraction, so I was tossing up between...
15
12208
by: Ingmar | last post by:
Simple comparison tests we have performed show that System.Math functions in C# are much slower than corresponding functions in C++. Extreme examples are System.Math.Exp() and System.Math.Tan(),...
12
12386
by: Janiek Buysrogge | last post by:
Hello, Does anyone know if there is a library or a sample project that can parse strings with mathematical expressions inside ? eg. string math = "(23 + 48) ^ 2 - (7.76 * 3.14)"; parser...
5
1591
by: Tom Gurath | last post by:
http://osnews.com/story.php?news_id=5602&page=2 This benchmark tests the Math & File I/O of 9 languages/run-times. Visual C++ (Version 7 - not managed) Visual C# gcc C Visual Basic.NET Visual...
13
3317
by: One | last post by:
hi group - I had this in a function - so I've just moved this out of the function for readabilty. Can someone please tell me WHY does this not return the result of : n1 times n2 As I said...
1
1286
by: Michael Fesser | last post by:
..oO(SM) <?php $itemsPerGroup = 10; $itemPosition = 12; $group = ceil($itemPosition/$itemsPerGroup); var_dump($group); ?>
0
7308
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7371
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
7023
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7479
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
4702
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3178
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1534
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
757
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
410
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.