RE: RegEx: Finding and replacing all characters between ( and ) ?

2001-06-07 Thread Ron Hartikka

Charles,

Can the () in your data be nested?

If so, you can't use an re. (See: How do I find matching/nesting anything?
in perlfaq 4.) For example,

while (DATA){

print;
print becomes\n;
s/\([^\)]+\)/()/g; # as Bill suggests
print;
print \n;

}
__DATA__
asdf(asdf)asdf
asdf((asdf))asdf

has the output...

asdf(asdf)asdf
becomes
asdf()asdf

asdf((asdf))asdf
becomes
asdf())asdf

I think you can use an re if you hard code a limit to the number of nests.

If you know there are no nested () you can use the re above.
If you know there is a limit to the nest depth, post the limit.
If you want to do unlimited nesting, you have to write a parser.


-Original Message-
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of
$Bill Luebkert
Sent: Thursday, June 07, 2001 12:35 AM
To: Charles Wilson (h)
Cc: [EMAIL PROTECTED]
Subject: Re: RegEx: Finding and replacing all characters between ( and )
?


Charles Wilson (h) wrote:

 I have been studying how to use Regular Expressions within my text editor
(Allaire's Coldfusion
 Studio- AKA Homesite).

 Specifically, I would like to find a left parenthese '(' then find a right
parenthese ')' in a file,
 and then delete out any amount of characters between the parentheses.  I'm
sure that using a Regular
 Expression to match the characters would be best, but I have tried all
different types of
 expressions such as:

 ((**))
 or
 ((*.*.*.*.*.*.))

 but it doesen't seem to work.

 Does anyone have any ideas?

Untested:

s/\([^\)]+\)/()/g;  # replace (...) with () multiple times (g)


--
  ,-/-  __  _  _ $Bill Luebkert   ICQ=14439852
 (_/   /  )// //   DBE Collectibles   http://www.todbe.com/
  / ) /--  o // //  Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/__/_/_http://www.freeyellow.com/members/dbecoll/
___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



RE: RegEx: Finding and replacing all characters between ( and ) ?

2001-06-07 Thread Joseph P. Discenza

Ron Hartikka wrote, on Thursday, June 07, 2001 8:33 AM
: Can the () in your data be nested?
:
: If so, you can't use an re. (See: How do I find matching/nesting anything?
: in perlfaq 4.) For example,
:
: while (DATA){
:
:   print;
:   print becomes\n;
:   s/\([^\)]+\)/()/g; # as Bill suggests

What if you make it
s/\([^\(\)]+\)|\(\(\)\)/()/g;
? You could also stick that in a while, print it at each iteration,
and watch the innermost parenthetical expressions disappear.

Joe

==
  Joseph P. Discenza, Sr. Programmer/Analyst
   mailto:[EMAIL PROTECTED]

  Carleton Inc.   http://www.carletoninc.com
  219.243.6040 ext. 300fax: 219.243.6060

Providing Financial Solutions and Compliance for over 30 Years


___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users



RE: RegEx: Finding and replacing all characters between ( and ) ?

2001-06-07 Thread Ron Hartikka

Ok

while (DATA){

print;
print becomes\n;
s/\([^\(\)]+\)|\(\(\)\)/()/g;
print;
print \n;

}
__DATA__
asdf(asdf)asdf
asdf((asdf))asdf
asdf(as(asdf)df)asdf

prints--

asdf(asdf)asdf
becomes
asdf()asdf

asdf((asdf))asdf
becomes
asdf(())asdf

asdf(as(asdf)df)asdf
becomes
asdf(as()df)asdf

- so, while what? -



-Original Message-
From: Joseph P. Discenza [mailto:[EMAIL PROTECTED]]
Sent: Thursday, June 07, 2001 8:53 AM
To: Ron Hartikka; perl win32 users
Subject: RE: RegEx: Finding and replacing all characters between ( and )
?


Ron Hartikka wrote, on Thursday, June 07, 2001 8:33 AM
: Can the () in your data be nested?
:
: If so, you can't use an re. (See: How do I find matching/nesting anything?
: in perlfaq 4.) For example,
:
: while (DATA){
:
:   print;
:   print becomes\n;
:   s/\([^\)]+\)/()/g; # as Bill suggests

What if you make it
s/\([^\(\)]+\)|\(\(\)\)/()/g;
? You could also stick that in a while, print it at each iteration,
and watch the innermost parenthetical expressions disappear.

Joe

==
  Joseph P. Discenza, Sr. Programmer/Analyst
   mailto:[EMAIL PROTECTED]

  Carleton Inc.   http://www.carletoninc.com
  219.243.6040 ext. 300fax: 219.243.6060

Providing Financial Solutions and Compliance for over 30 Years



___
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users