How to get rid of the regex????

E

Extremest

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

Markus Stoeger

Extremest said:
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
 
E

Extremest

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
 
J

Jon Skeet [C# MVP]

Extremest said:
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.
 
E

Extremest

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.
 
J

Jon Skeet [C# MVP]

Extremest said:
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
 

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