regular expression trouble

Programming, for all ages and all languages.
Post Reply
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

regular expression trouble

Post by Zacariaz »

Hi. The forum that I normally take this tedious stuff to has changed something and now I can't login, so I hope you'll forgive this.

Basically, it's all about regular expressions, though in C#, which hopefully won't make a difference.

I'm trying to match an entire line, which may be structured in a very specific, though somewhat complicate way.

To illustrate my issue I'll simply give two examples:

Code: Select all

2011-03-22 20:28:43 [Team]
2011-03-22 20:28:43 [Local]
NB, these lines are cut of at the end so ']' does not mark the end of the string.

The first part is easy enough, though it may be done in a better way:

Code: Select all

^\d\d\d\d\-\d\d\-\d\d \d\d:\d\d:\d\d 
Here it shows clearly that I've never worked much with regular expressions before, but I'm learning fast.

Now the next part is more tricky. Initially I thought that

Code: Select all

\[[/Team//Local/]\]
would do the trick, but after testing it is clear that something is very wrong. Then I considered \b, but that obviously didn't work and so on and so forth. I've spend the better part of the day figuring out how to do this, but with no luck. Any tutorial or guide I've found have left out the stuff I need to know, or else I'm just... Well, not as clever as I thought I was.

This is the only trouble I've got by the way.

Hope you'll help me. Kind of in a hurry.


Best regards.
This was supposed to be a cool signature...
User avatar
Zacariaz
Member
Member
Posts: 1069
Joined: Tue May 22, 2007 2:36 pm
Contact:

Re: regular expression trouble

Post by Zacariaz »

Seems like I've finally figured it out:

Code: Select all

\[(Team|Local)\]
If you see a problem, please let me know, otherwise just disregard this thread as one of my usual ramblings.

Thanks.
This was supposed to be a cool signature...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: regular expression trouble

Post by Solar »

Looks good.

Hint: \d{4}...
Every good solution is obvious once you've found it.
Post Reply