473,388 Members | 897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

Quick regex question

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

Aug 24 '06 #1
7 2547
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.IgnoreCase);

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.IgnoreCase);

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

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.IgnoreCase);
Debug.WriteLine(re.Replace(@"c:\test.dir\as.as\tes t.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
by: Du Dang | last post by:
Text: ===================== <script1> ***stuff A </script1> ***more stuff <script2> ***stuff B
4
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...
1
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? ...
17
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 ...
5
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...
5
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------ ' <autogenerated> ' This code was generated...
6
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"....
10
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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,...
0
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 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.