By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,011 Members | 1,000 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,011 IT Pros & Developers. It's quick & easy.

Quick regex question

P: n/a
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
Share this Question
Share on Google+
7 Replies


P: n/a
But good to see that we will match both upper-case and lower-case numbers
<g>
Aug 24 '06 #2

P: n/a
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

P: n/a
(, ) 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

P: n/a
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

P: n/a
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

P: n/a
... 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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.