469,926 Members | 1,497 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,926 developers. It's quick & easy.

How to get rid of the regex????

I have a huge regex setup going on. If I don't do each one by itself
instead of all in one it won't work for. Also would like to know if
there is a faster way tried to use string.replace with all the right
parts in there in one big line and for some reason that did not work
either. Here is my regex's.

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 txt = new Regex("\\.txt.*",
RegexOptions.IgnoreCase);
static Regex jpg = new Regex("\\.jpg.*",
RegexOptions.IgnoreCase);
static Regex png = new Regex("\\.png.*",
RegexOptions.IgnoreCase);
static Regex gif = new Regex("\\.gif.*",
RegexOptions.IgnoreCase);
static Regex zip = new Regex("\\.zip.*",
RegexOptions.IgnoreCase);
static Regex wma = new Regex("\\.wma.*",
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 ts = new
Regex("\\.\\d{4}\\.ts|\\.\\d{2}\\.ts|\\.ts", RegexOptions.IgnoreCase);

Aug 24 '06 #1
6 2290
Extremest wrote:
I have a huge regex setup going on. If I don't do each one by itself
instead of all in one it won't work for. Also would like to know if
there is a faster way tried to use string.replace with all the right
parts in there in one big line and for some reason that did not work
either. Here is my regex's.
What are you trying to do? Its hard to help you improve the code without
known what it should do.

Max
Aug 24 '06 #2
ok I get a header into a class when it is created. I need to go
through the header and just remove what is in the regex's. I jsut use
the regex.replace method. I tried to use the string method but seemed
to not like it. It made the whole thing fail. Not crash just never
gave out a value for some reason. I tried to do something like this.

this.filename = this.filename.Replace(".rar", "").Replace(".avi",
"");etc etc

Aug 24 '06 #3
Extremest <dn**********@charter.netwrote:
ok I get a header into a class when it is created. I need to go
through the header and just remove what is in the regex's. I jsut use
the regex.replace method. I tried to use the string method but seemed
to not like it. It made the whole thing fail. Not crash just never
gave out a value for some reason. I tried to do something like this.

this.filename = this.filename.Replace(".rar", "").Replace(".avi",
"");etc etc
That should work fine - although I'd set up an array or list of the
file extensions you want to remove, to make life easier.

Could you post a short but complete program which demonstrates the
problem?

See http://www.pobox.com/~skeet/csharp/complete.html for details of
what I mean by that.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Aug 24 '06 #4
Why not put them all in a single Regex expression using the OR ( | ) operator?
Peter

--
Co-founder, Eggheadcafe.com developer portal:
http://www.eggheadcafe.com
UnBlog:
http://petesbloggerama.blogspot.com


"Extremest" wrote:
I have a huge regex setup going on. If I don't do each one by itself
instead of all in one it won't work for. Also would like to know if
there is a faster way tried to use string.replace with all the right
parts in there in one big line and for some reason that did not work
either. Here is my regex's.

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 txt = new Regex("\\.txt.*",
RegexOptions.IgnoreCase);
static Regex jpg = new Regex("\\.jpg.*",
RegexOptions.IgnoreCase);
static Regex png = new Regex("\\.png.*",
RegexOptions.IgnoreCase);
static Regex gif = new Regex("\\.gif.*",
RegexOptions.IgnoreCase);
static Regex zip = new Regex("\\.zip.*",
RegexOptions.IgnoreCase);
static Regex wma = new Regex("\\.wma.*",
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 ts = new
Regex("\\.\\d{4}\\.ts|\\.\\d{2}\\.ts|\\.ts", RegexOptions.IgnoreCase);

Aug 24 '06 #5
I tried putting them all in one regex and the regex does not work right
anymore for some reason. Might be a bug with 2.0 not sure. I have
tried to use the string method and that has failed also the regex works
just not as nice of code for me. Speed it really hasn't slowed it down
to much. Takes the db longer to sort then for the regex to work.

Aug 24 '06 #6
Extremest wrote:
I tried putting them all in one regex and the regex does not work right
anymore for some reason. Might be a bug with 2.0 not sure. I have
tried to use the string method and that has failed also the regex works
just not as nice of code for me. Speed it really hasn't slowed it down
to much. Takes the db longer to sort then for the regex to work.
Given that you're doing two common things and both of them are failing
for you, it seems more likely that it's a bug in your code than a bug
in the framework. In particular, string.Replace works absolutely fine.

Please post a short but complete example to reproduce the problem.

Jon

Aug 24 '06 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Tim Conner | last post: by
20 posts views Thread by jeevankodali | last post: by
17 posts views Thread by clintonG | last post: by
7 posts views Thread by Extremest | last post: by
3 posts views Thread by aspineux | last post: by
15 posts views Thread by morleyc | last post: by
reply views Thread by Karch | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.