hy,
i've got a simple question (for somebody who already knows the answer)
about regex:
i've a string like bla@bla@bla or bla@@bla
i like to check the @'s, but couldn't figure it out how to set zero or
more char's. (zero or one was easy).
thank's
rené 14 2262
rene,
Are you sure that a regular expression is the best option here? Why not
just call the Split method, passing the '@' character as the delimiter?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m
"ohmmega" <sh****@gmx.atw rote in message
news:11******** **************@ b79g2000hse.goo glegroups.com.. .
hy,
i've got a simple question (for somebody who already knows the answer)
about regex:
i've a string like bla@bla@bla or bla@@bla
i like to check the @'s, but couldn't figure it out how to set zero or
more char's. (zero or one was easy).
thank's
rené
Hello ohmmega,
hy,
i've got a simple question (for somebody who already knows the answer)
about regex:
i've a string like bla@bla@bla or bla@@bla
i like to check the @'s, but couldn't figure it out how to set zero or
more char's. (zero or one was easy).
thank's
rené
What do you mean by 'I like to check the @'s'
Going from the fact that the rest of that sentence continues about soemthing
that sounds like a quantifier here's a short overview of the different quantifiers
available:
- ? - Zero or One
- * - Zero or More
- + - One or more
- {0,n} - Zero to n
- {n,} - n or more
- {n,m} - n to m
Take your pick ;)
Other than this being a question about regular expressions, you've not explained
what you wan to do with the end result. Regex is a pretty expensive tool
to use in terms of cpu power and in some scenario's memory consumption. Are
you sure it's the tool for the job? If you could explain a little about what
you're trying to achieve, we could potentially help you with a better solution.
Jesse
Hi,
I'm not sure what you mean with "check", what do you want to do when you
find a @ ?
"ohmmega" <sh****@gmx.atw rote in message
news:11******** **************@ b79g2000hse.goo glegroups.com.. .
hy,
i've got a simple question (for somebody who already knows the answer)
about regex:
i've a string like bla@bla@bla or bla@@bla
i like to check the @'s, but couldn't figure it out how to set zero or
more char's. (zero or one was easy).
thank's
rené
On Mon, 06 Aug 2007 13:49:32 -0000, ohmmega <sh****@gmx.atw rote:
>hy,
i've got a simple question (for somebody who already knows the answer) about regex: i've a string like bla@bla@bla or bla@@bla i like to check the @'s, but couldn't figure it out how to set zero or more char's. (zero or one was easy).
thank's rené
this may help http://sourceforge.net/projects/regulator/
i need to know if there are exactly 5 @'s with or without text in
beetween.
i thought compiled regex would be faster than splitting and .length.
nethertheless, if you guy's say "OH NO!!!", i've no reason to demand
on it.
On Aug 7, 9:23 am, ohmmega <sho...@gmx.atw rote:
i need to know if there are exactly 5 @'s with or without text in
beetween.
i thought compiled regex would be faster than splitting and .length.
nethertheless, if you guy's say "OH NO!!!", i've no reason to demand
on it.
How much do you care about performance in this case? How often are you
likely to call this? Have you measured the performance of Split and
found that it doesn't meet your requirements?
Jon
On 7 Aug., 11:00, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
On Aug 7, 9:23 am, ohmmega <sho...@gmx.atw rote:
i need to know if there are exactly 5 @'s with or without text in
beetween.
i thought compiled regex would be faster than splitting and .length.
nethertheless, if you guy's say "OH NO!!!", i've no reason to demand
on it.
How much do you care about performance in this case? How often are you
likely to call this? Have you measured the performance of Split and
found that it doesn't meet your requirements?
Jon
i need this about 200 times in a time critical application, so i just
want to have the best option.
i've not measured the time yet, but that's a good point - i will try
this next.
thanks so far
rené
Hello ohmmega,
On 7 Aug., 11:00, "Jon Skeet [C# MVP]" <sk...@pobox.co mwrote:
>On Aug 7, 9:23 am, ohmmega <sho...@gmx.atw rote:
>>i need to know if there are exactly 5 @'s with or without text in beetween. i thought compiled regex would be faster than splitting and .length. nethertheless , if you guy's say "OH NO!!!", i've no reason to demand on it.
How much do you care about performance in this case? How often are you likely to call this? Have you measured the performance of Split and found that it doesn't meet your requirements?
Jon
i need this about 200 times in a time critical application, so i just
want to have the best option.
i've not measured the time yet, but that's a good point - i will try
this next.
thanks so far
rené
If you still want to go the regex way, you basically have two options:
See if you can find a match for this:
^[^@]*(@[^@]*){5}$
Or do a Regex.Replace and replace everything that't not a @ with nothing
and measure the length of the text afterwards:
Regex.Replace(i nputstring, "[^@]", "").Length 5
When using a regular expression, make sure you're usign a static instance
with the option RegexOption.Com piled set for performance reasons.
Like this
private static Regex rx = new Regex(pattern, RegexOptions.Co mpiled);
then reference this instance when using the expression.
Also add a static constructor to the class which calls rx.Match("");, that
way your performance needy code will not suffer the recompilation of the
regex.
You can also use a tool like The Regulator to generate an Assembly with the
compiled regex in there. This would give you the performance boost of not
having the regex compiled from the executable at all.
Even though this is a nice excercise in Regular expressions, I think that
simple string manupulations would be much faster...
public bool HasFiveAts(stri ng input)
{
int count = 0;
foreach(char c in inputstring)
{
if (c == '@') { count++; }
// might even test for if (count 5) {return false;}, but you'd have
to test that for performance
}
return count == 5
}
A string is an array of char. I believe the fastedst way would be to loop
through the chars in the string, and count the '@' chars. Once you reach 5,
you return true. If you reach the end of the string without reaching 5, you
return false.
--
HTH,
Kevin Spencer
Microsoft MVP
Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries: http://www.miradyne.net
"ohmmega" <sh****@gmx.atw rote in message
news:11******** **************@ r34g2000hsd.goo glegroups.com.. .
i need to know if there are exactly 5 @'s with or without text in
beetween.
i thought compiled regex would be faster than splitting and .length.
nethertheless, if you guy's say "OH NO!!!", i've no reason to demand
on it.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jon Maz |
last post by:
Hi All,
Am getting frustrated trying to port the following (pretty simple) function
to CSharp. The problem is that I'm lousy at Regular Expressions....
//from http://support.microsoft.com/default.aspx?scid=kb;EN-US;246800
function fxnParseIt()
{
var sInputString = 'asp and database';
|
by: Tim Conner |
last post by:
Is there a way to write a faster function ?
public static bool IsNumber( char Value )
{
if (Regex.IsMatch( Value.ToString(), @"^+$" ))
{
return true;
}
else return false;
}
|
by: jeevankodali |
last post by:
Hi
I have an .Net application which processes thousands of Xml nodes each
day and for each node I am using around 30-40 Regex matches to see if
they satisfy some conditions are not. These Regex matches are called
within a loop (like if or for). E.g.
for(int i = 0; i < 10; i++)
{
Regex r = new Regex();
|
by: clintonG |
last post by:
I'm using an .aspx tool I found at but as nice as the interface is I
think I need to consider using others. Some can generate C# I understand.
Your preferences please...
<%= Clinton Gallagher
http://forta.com/books/0672325667/
|
by: Extremest |
last post by:
I have a huge regex setup going on. If I don't do each one by itself
instead of all in one it won't work for. Also would like to know if
there is a faster way tried to use string.replace with all the right
parts in there in one big line and for some reason that did not work
either. Here is my regex's.
static Regex rar = new Regex("\\.part.*",
RegexOptions.IgnoreCase);
static Regex par = new Regex("\\.vol.*",
RegexOptions.IgnoreCase);
| |
by: Extremest |
last post by:
I am using this regex.
static Regex paranthesis = new Regex("(\\d*/\\d*)",
RegexOptions.IgnoreCase);
it should find everything between parenthesis that have some numbers
onyl then a forward slash then some numbers. For some reason I am not
getting that. It won't work at all in 2.0
|
by: aspineux |
last post by:
My goal is to write a parser for these imaginary string from the SMTP
protocol, regarding RFC 821 and 1869.
I'm a little flexible with the BNF from these RFC :-)
Any comment ?
tests=
def RN(name, regex):
"""protect using () and give an optional name to a regex"""
if name:
|
by: morleyc |
last post by:
Hi, i would like to remove a number of characters from my string (\t
\r \n which are throughout the string), i know regex can do this but i
have no idea how. Any pointers much appreciated.
Chris
|
by: CJ |
last post by:
Is this the format to parse a string and return the value between the item?
Regex pRE = new Regex("<File_Name>.*>(?<insideText>.*)</File_Name>");
I am trying to parse this string.
<File_Name>Services</File_Name>
Thanks
|
by: Karch |
last post by:
I have these two methods that are chewing up a ton of CPU time in my
application. Does anyone have any suggestions on how to optimize them or
rewrite them without Regex? The most time-consuming operation by a long-shot
is the regex.Replace. Basically the only purpose of it is to remove spaces
between opening/closing tags and the element name. Surely there is a better
way.
private string FixupJavascript(string htmlCode)
{
string result...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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 we have to send another system
| |
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |