need help for regular expression

L

Li Chen

Hi all,

I wonder what is the regular expression for this line. What I try to do
is to remove "(some text here)" from a long string.


Thanks,

Li


string=......(some text here).......
 
D

dusty

Hi all,

I wonder what is the regular expression for this line. What I try to do
is to remove "(some text here)" from a long string.

Thanks,

Li

string=......(some text here).......

This works.

"......(some text here).......".sub('(some text here)','')
 
C

Chris Shea

Hi all,

I wonder what is the regular expression for this line. What I try to do
is to remove "(some text here)" from a long string.

Thanks,

Li

string=......(some text here).......

Li,

Well, there are few different ways.

string.sub!(/\(.*?\)/,'')
string.sub!(/\([^)]*\)/,'')

If there's a chance that there will be nested parentheses, you'll need
something more complicated.

It seems like you're often asking regular expression questions. I'd
highly recommend picking up Mastering Regular Expressions by Jeffrey
Friedl. After reading just the first two chapters, you'll be able to
figure stuff like this out very easily. After reading a few more
chapters, you'll know the difference between the two expressions above
and which one you want to use.

HTH,
Chris
 
L

Li Chen

Chris said:
Li,

Well, there are few different ways.

string.sub!(/\(.*?\)/,'')
string.sub!(/\([^)]*\)/,'')

If there's a chance that there will be nested parentheses, you'll need
something more complicated.

It seems like you're often asking regular expression questions. I'd
highly recommend picking up Mastering Regular Expressions by Jeffrey
Friedl. After reading just the first two chapters, you'll be able to
figure stuff like this out very easily. After reading a few more
chapters, you'll know the difference between the two expressions above
and which one you want to use.

HTH,
Chris


Hi Chris,

Thank you very much. I will take a look at "Mastering Regular
Expressions".

Li
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,776
Messages
2,569,603
Members
45,197
Latest member
Sean29G025

Latest Threads

Top