Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / October 2006

Tip: Looking for answers? Try searching our database.

RegEx to find a word not enclosed in paranthesis

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
vmoreau@gmail.com - 31 Oct 2006 16:40 GMT
I have a text and I need to find a Word that are not enclosed in
paranthesis. Can it be done with a regex? Is someone could help me?
I am not familar with regex...

Example looking for WORD:
(there is a WORD in ( my string WORD )) and * WORD * to (find WORD)
and * WORD *

Should give me the to word between star (star ar not part of string)

thanks a lot
Jason Gurtz - 31 Oct 2006 17:26 GMT
> I have a text and I need to find a Word that are not enclosed in
> paranthesis.

Did you try character classes.  This'll givu an idea to get started:

[^(]WORD[^)]

~Jason

--
Chris Fulstow - 31 Oct 2006 17:42 GMT
> I have a text and I need to find a Word that are not enclosed in
> paranthesis. Can it be done with a regex? Is someone could help me?
[quoted text clipped - 7 lines]
>
> thanks a lot
Chris Fulstow - 31 Oct 2006 17:45 GMT
I like this method :)

StringBuilder sb = new StringBuilder();
int depth = 0;
foreach (char c in str)
{
   if (c == '(') depth++;
   else if (c == ')') depth--;
   else if (depth == 0) sb.Append(c);
}

string noParentheses = sb.ToString();

--
Chris Fulstow
MCP, MCTS
http://chrisfulstow.blogspot.com/

> I have a text and I need to find a Word that are not enclosed in
> paranthesis. Can it be done with a regex? Is someone could help me?
[quoted text clipped - 7 lines]
>
> thanks a lot
Martin Z - 31 Oct 2006 19:16 GMT
Chris' method is best, since regexes don't deal well with recursive
concepts.  After all, you don't want to just consider the case of "am I
in parentheses" - you have to be able to handle that in
((((( foo )))) bar (((( baz )))))
bar is within the outermost set of parens.

> I like this method :)
>
[quoted text clipped - 25 lines]
> >
> > thanks a lot

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.