Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
need help for regular expression
Li Chen
7/2/2008 9:47:00 PM
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).......
--
Posted via
http://www.ruby-...
.
3 Answers
dusty
7/2/2008 11:00:00 PM
0
On Jul 2, 5:46 pm, Li Chen <chen_...@yahoo.com> wrote:
> 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).......
> --
> Posted via
http://www.ruby-...
.
This works.
"......(some text here).......".sub('(some text here)','')
Chris Shea
7/2/2008 11:00:00 PM
0
On Jul 2, 3:46 pm, Li Chen <chen_...@yahoo.com> wrote:
> 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).......
> --
> Posted via
http://www.ruby-...
.
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
Li Chen
7/2/2008 11:18:00 PM
0
Chris Shea wrote:
> On Jul 2, 3:46?pm, Li Chen <chen_...@yahoo.com> wrote:
>> --
>> Posted via
http://www.ruby-...
.
>
> 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
--
Posted via
http://www.ruby-...
.
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
need help for regular expression
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password