Page 1 of 1

regular expression trouble

Posted: Fri Mar 25, 2011 12:36 pm
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.

Re: regular expression trouble

Posted: Fri Mar 25, 2011 12:53 pm
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.

Re: regular expression trouble

Posted: Mon Mar 28, 2011 1:58 am
by Solar
Looks good.

Hint: \d{4}...