473,703 Members | 3,018 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Quick regex question

I am using this regex.

static Regex paranthesis = new Regex("(\\d*/\\d*)",
RegexOptions.Ig noreCase);

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

Aug 24 '06 #1
7 2584
But good to see that we will match both upper-case and lower-case numbers
<g>
Aug 24 '06 #2
lol..was in such a hurry when doing that I didn't even think about it.
Too used to matching on text.
Marc Gravell wrote:
But good to see that we will match both upper-case and lower-case numbers
<g>
Aug 24 '06 #3
(, ) and / also need escaping with a \ (or 2 inside a string, if you see
what I mean); also - you might mean + rather than *, otherwise the following
will match:
(1/1) right?
(1/) wrong?
(/2) wrong?
(/) wrong?

Try: new Regex(@"\(\d+\/\d+\)", RegexOptions.Ig noreCase);

Marc
Aug 24 '06 #4
that worked perfect for ()'s and for []'s thinks a lot.

Marc Gravell wrote:
(, ) and / also need escaping with a \ (or 2 inside a string, if you see
what I mean); also - you might mean + rather than *, otherwise the following
will match:
(1/1) right?
(1/) wrong?
(/2) wrong?
(/) wrong?

Try: new Regex(@"\(\d+\/\d+\)", RegexOptions.Ig noreCase);

Marc
Aug 24 '06 #5
Any way you could help me to speed up these regex's. I can't get them
to work right as one. The one at the bottom is the only one that will
work as one. It pretty much jsut remove the ext on most but on some
has to remove just before the extension depening on what it is.

static Regex rar = new Regex("\\.part. *", RegexOptions.Ig noreCase);
static Regex par = new Regex("\\.vol.* ",
RegexOptions.Ig noreCase);
static Regex par2 = new Regex("\\.par.* ",
RegexOptions.Ig noreCase);
static Regex rar2 = new Regex("\\.r\\d* ",
RegexOptions.Ig noreCase);
static Regex rar5 = new Regex("\\.s\\d* ",
RegexOptions.Ig noreCase);
static Regex rar3 = new Regex("\\.rar.* ",
RegexOptions.Ig noreCase);
static Regex nfo = new Regex("\\.nfo.* ",
RegexOptions.Ig noreCase);
static Regex sfv = new Regex("\\.sfv.* ",
RegexOptions.Ig noreCase);
static Regex m2v = new Regex("\\.m2v.* ",
RegexOptions.Ig noreCase);
static Regex vob = new Regex("\\.vob.* ",
RegexOptions.Ig noreCase);
static Regex avi = new Regex("\\.avi.* ",
RegexOptions.Ig noreCase);
static Regex nzb = new Regex("\\.nzb.* ",
RegexOptions.Ig noreCase);
static Regex rar4 = new Regex("\\.\\d{3 }",
RegexOptions.Ig noreCase);
static Regex log = new Regex("\\.log.* ",
RegexOptions.Ig noreCase);
static Regex dat = new Regex("\\.dat.* ",
RegexOptions.Ig noreCase);
static Regex iso = new Regex("\\.iso.* ",
RegexOptions.Ig noreCase);
static Regex cue = new Regex("\\.cue.* ",
RegexOptions.Ig noreCase);
static Regex bin = new Regex("\\.bin.* ",
RegexOptions.Ig noreCase);
static Regex rar6 = new Regex("\\.t\\d* ",
RegexOptions.Ig noreCase);
static Regex ts = new
Regex("\\.\\d{4 }\\.ts|\\.\\d{2 }\\.ts|\\.ts", RegexOptions.Ig noreCase);

Aug 24 '06 #6
... work right as one.
... work as one.
One what? Well, there isn't much clue what they are meant to match! Or how
they are to be used... e.g. if you want to use Replace(), you may need to
mark sections - e.g. (using .avi):

Regex re = new Regex(@"^(.*)(\ .avi)$", RegexOptions.Ig noreCase);
Debug.WriteLine (re.Replace(@"c :\test.dir\as.a s\test.name.avi ", "$1"));

outputs "c:\test.dir\as .as\test.name"; you can use different bracketed
sections (and $ symbols) to read/write different things.

But - a: I'm just simply not going to debug 20 Regex expressions here,
especially if it isn't clear what they are trying to do! Maybe one or two
*if* you indicate what it should match and what is failing. Otherwise, I
suggest you google for a good Regex dictionary...

Marc
Aug 24 '06 #7
What I meant is they work fine by themselves. That is how I have it
running now. But if I try to use just one regex with the | inbetween
each one it don't seem to work right. I will see if I can find a good
regex dictionary online. So far I haven't.

Aug 24 '06 #8

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

Similar topics

6
396
by: Du Dang | last post by:
Text: ===================== <script1> ***stuff A </script1> ***more stuff <script2> ***stuff B
4
3601
by: Alex Moskalyuk | last post by:
We have a filename, which could theoretically be something like verylongfilename.2004.05.11.txt. We just need the significant part before the first dot. My solution was a quick regexp: filename = (Regex.Split(filename, ".")); Is there a better way to handle it? Maybe something built in? --
1
1457
by: K. Shier | last post by:
while writing a RegEx, you implicily name your Groups: \b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b so, why isn't .Name a property of a System.Text.RegularExpressions.RegEx.Group? more importantly, how can you refer to a Group by name in code?
17
3971
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/
5
1133
by: Troy | last post by:
Hello, I'd like to validate an input my from user i.e. make sure that the user enters the phone number is the following formats (XXX) XXX-XXXX XXX-XXX-XXXX Any ideas on how I can achieve this with regular expressions? Having difficulty wrapping my head around it.
5
5098
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated by a tool. ' Runtime Version: 1.1.4322.2032 ' ' Changes to this file may cause incorrect behavior and will be lost if ' the code is regenerated. ' </autogenerated>
6
5892
by: Martin Evans | last post by:
Sorry, yet another REGEX question. I've been struggling with trying to get a regular expression to do the following example in Python: Search and replace all instances of "sleeping" with "dead". This parrot is sleeping. Really, it is sleeping. to This parrot is dead. Really, it is dead.
10
2117
by: yoni | last post by:
Hey, i am trying to get to the right regexp to remove everything that's a multi line comment. in other words, everything between \*...*/. my expression is: /\*.*\*/ Doesnt work... Anybody sees anything wrong with that? thanks
2
1464
Xx r3negade
by: Xx r3negade | last post by:
Hi, I am very bad with regexes. I need a regular expression that will reduce a url like this: hxxp://example.com/somefolder/something/whatever to its base: hxxp://example.com The two slashes after the http: complicate things. I know I could just remove the "http://" and add it again later, but as a learning experience, I would like to do this regex in a single line.
0
8759
marktang
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...
0
9251
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9122
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 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...
0
8963
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7872
agi2029
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...
1
6588
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4687
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2453
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2069
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 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...

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.