Regex question

  • Thread starter Thread starter Nightcrawler
  • Start date Start date
N

Nightcrawler

I have the following regex:

(?:(?<Title>.+)??(?<Remix>(?:\([^\)]+\)|\[[^\]]+\]))|(?<Title>.+))

This matches

title
title (remix)
title [remix]

How can I extend this to also match

title - remix

I also want the regex not to be sensitive to the amount of spacing
before and after the dash.

Thanks
 
Nightcrawler,

It's hard to help you with the actual regex, since your requirements
aren't completely clear to me. However, what often helps me with
regexes, is to split them across a few lines of code to improve
readability (use Stringbuilder or +=, according to your need for
speed).

Each line would have a part of the string you're trying to match. It
seems to me you need:

1. start of the string (?)
2. "title", exactly that string
3. 0...many whitespace characters
4. either a "-" or a "(" or a "[" character
5. "remix", exactly that string
6. optionally, either a ")" or a "]"
7. end of the string (?)

Perhaps the above will help you refine requirements, and then write
the regex yourself. I really suggest splitting the regex in your code
into separated parts as well, this greatly helps folks (including
yourself) read back a regular expression.

Regards,
Jeroen
 
Nightcrawler said:
I have the following regex:

(?:(?<Title>.+)??(?<Remix>(?:\([^\)]+\)|\[[^\]]+\]))|(?<Title>.+))

This matches

title
title (remix)
title [remix]

How can I extend this to also match

title - remix

I also want the regex not to be sensitive to the amount of spacing
before and after the dash.

Thanks

my advice to you is to find a regex tester and work it out yourself, an
example of a regex tester can be found below...

http://www.codeproject.com/KB/dotnet/expresso.aspx
 
Back
Top