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. 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
"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: \( \) \+
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
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
[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 This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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: *** ...
|
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,...
|
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...
|
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...
|
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(),...
| |
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...
|
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...
|
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...
|
by: Michael Fesser |
last post by:
..oO(SM)
<?php
$itemsPerGroup = 10;
$itemPosition = 12;
$group = ceil($itemPosition/$itemsPerGroup);
var_dump($group);
?>
|
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,...
|
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...
| |
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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 ...
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| | |