472,351 Members | 1,478 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,351 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 2442
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...
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...
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....
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...
5
by: Chris | last post by:
How Do I use the following auto-generated code from The Regulator? '------------------------------------------------------------------------------...
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...
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...
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 ...
0
better678
by: better678 | last post by:
Question: Discuss your understanding of the Java platform. Is the statement "Java is interpreted" correct? Answer: Java is an object-oriented...
0
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge...
0
jalbright99669
by: jalbright99669 | last post by:
Am having a bit of a time with URL Rewrite. I need to incorporate http to https redirect with a reverse proxy. I have the URL Rewrite rules made...
0
by: Matthew3360 | last post by:
Hi there. I have been struggling to find out how to use a variable as my location in my header redirect function. Here is my code. ...
2
by: Matthew3360 | last post by:
Hi, I have a python app that i want to be able to get variables from a php page on my webserver. My python app is on my computer. How would I make it...
0
hi
by: WisdomUfot | last post by:
It's an interesting question you've got about how Gmail hides the HTTP referrer when a link in an email is clicked. While I don't have the specific...
0
by: Matthew3360 | last post by:
Hi, I have been trying to connect to a local host using php curl. But I am finding it hard to do this. I am doing the curl get request from my web...
0
Oralloy
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the...
0
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand....

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.