Click here to Skip to main content
15,890,512 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi everybody,

I have this code:
C#
string Test = @"[Name]Hello";
Regex Finder = new Regex(@"^[\S]");
var Matches = Finder.Matches(Test);
string From = Matches[0].ToString();


I execute the code, but the result is the same: just the '[' is extracted in the string from. I have tried even with Matches[0].value, but nothing chages...

What's wrong with my regex?

Thanks in advance...

LG

PS: I actually need to find any character inside the square brackets, so I have also written the regex ^[.*], but does not return anything if the string is [Name Surname]Hello.
Posted
Comments
LLLLGGGG 3-Jan-15 14:46pm    
I actually have solved my problem: the real regex is ^\[.*\].

LG
Add this as answer. :)

I have solved my problem: the actual regex is \[[^\]]*] (I have solved it yesterday evening, but I had another little problem to solve, and this is the solution for a stirng of this type [author][date]Comment, it extracts [author] and [date].
 
Share this answer
 
Answered only to remove from the unanswered list: solved by OP.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900