PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > gsub question on special charaters
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
gsub question on special charaters

Réponse
 
LinkBack Outils de la discussion
Vieux 20/11/2007, 18h18   #1
Robert Keller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut gsub question on special charaters


I have a string that looks like this :

ts = "^LThe beginning of the sentence"

I want to remove the "^L"

I've tried

ts.gsub!(/^[\^L]/,'')

which removes the "^", but I need to remove the "^L" when they are
together and at the beginning of the sentence.

Any is welcome


--
Robert Keller
--------------------------------------------------
robert.keller@yahoo.com


  Réponse avec citation
Vieux 20/11/2007, 18h24   #2
Phrogz
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gsub question on special charaters

On Nov 20, 11:18 am, Robert Keller <rlkel...@yahoo.com> wrote:
> I have a string that looks like this :
>
> ts = "^LThe beginning of the sentence"
>
> I want to remove the "^L"
>
> I've tried
>
> ts.gsub!(/^[\^L]/,'')
>
> which removes the "^", but I need to remove the "^L" when they are
> together and at the beginning of the sentence.


irb(main):001:0> ts = "^LThe beginning of the sentence"
=> "^LThe beginning of the sentence"
irb(main):002:0> ts.sub /^\^L/, ''
=> "The beginning of the sentence"

Also:
1) Do you really mean ^ (start of line) or do you mean \A (start of
string)?
2) No need to use gsub if there's only ever going to be a single
match.
  Réponse avec citation
Vieux 20/11/2007, 18h31   #3
Ben Atkin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gsub question on special charaters

Yours doesn't work because characters in the square brackets can't be
escaped. Instead of matching that character, it will match "\", "^",
or "L". Phrogz has the right answer; just thought I'd explain why his
works and yours doesn't.

Ben

On Nov 20, 2007 11:18 AM, Robert Keller <rlkeller@yahoo.com> wrote:
>
> I have a string that looks like this :
>
> ts = "^LThe beginning of the sentence"
>
> I want to remove the "^L"
>
> I've tried
>
> ts.gsub!(/^[\^L]/,'')
>
> which removes the "^", but I need to remove the "^L" when they are
> together and at the beginning of the sentence.
>
> Any is welcome
>
>
> --
> Robert Keller
> --------------------------------------------------
> robert.keller@yahoo.com
>
>
>




--
Ben Atkin
ben@benatkin.com
http://www.benatkin.com/

  Réponse avec citation
Vieux 20/11/2007, 20h29   #4
Robert Keller
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: gsub question on special charaters

Note: parts of this message were removed by the gateway to make it a legal Usenet post.

Thanks! The explanation ed. I just ordered
Mastering Regular Expressions
<http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1195585371&sr= 1-1>


Mastering Regular Expressions
<http://www.amazon.com/Mastering-Regular-Expressions-Jeffrey-Friedl/dp/0596528124/ref=pd_bbs_sr_1?ie=UTF8&s=books&qid=1195585371&sr= 1-1>
by Jeffrey Friedl


--
Robert Keller
--------------------------------------------------
robert.keller@yahoo.com



Ben Atkin wrote:
> Yours doesn't work because characters in the square brackets can't be
> escaped. Instead of matching that character, it will match "\", "^",
> or "L". Phrogz has the right answer; just thought I'd explain why his
> works and yours doesn't.
>
> Ben
>
> On Nov 20, 2007 11:18 AM, Robert Keller <rlkeller@yahoo.com> wrote:
>
>> I have a string that looks like this :
>>
>> ts = "^LThe beginning of the sentence"
>>
>> I want to remove the "^L"
>>
>> I've tried
>>
>> ts.gsub!(/^[\^L]/,'')
>>
>> which removes the "^", but I need to remove the "^L" when they are
>> together and at the beginning of the sentence.
>>
>> Any is welcome
>>
>>
>> --
>> Robert Keller
>> --------------------------------------------------
>> robert.keller@yahoo.com
>>
>>
>>
>>

>
>
>
>


  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 07h14.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11945 seconds with 12 queries