Quick regex question

E

Extremest

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
 
M

Marc Gravell

(, ) 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
 
E

Extremest

lol..was in such a hurry when doing that I didn't even think about it.
Too used to matching on text.
 
E

Extremest

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);
 
M

Marc Gravell

... 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\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
 
E

Extremest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top