[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

regex question

rlkeller

11/1/2007 6:31:00 PM

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

I have a string = "this is text that I want to 9 9.90 89 9 ii8 u"

using str = string.gsub(/(?!\d)\b\s\b(?!\d)/,'-')

i get "this-is-text-that I want-to 9 9.90 89 9-ii8-u"
^ ^

there problem is that I do not want the "-" to show up if the last char is a digit or the first chat is a digit. Got real close, but I think I need lookbehind which is not supported in ruby?

------------------------------
Robert Keller
rlkeller@yahoo.com


16 Answers

Jim Weirich

11/1/2007 7:20:00 PM

0

Robert Keller wrote:
> I have a string = "this is text that I want to 9 9.90 89 9 ii8 u"
>
> using str = string.gsub(/(?!\d)\b\s\b(?!\d)/,'-')
>
> i get "this-is-text-that I want-to 9 9.90 89 9-ii8-u"
> ^ ^
>
> there problem is that I do not want the "-" to show up if the last char
> is a digit or the first chat is a digit. Got real close, but I think I
> need lookbehind which is not supported in ruby?

Is this what you want:

str.gsub(/([^0-9])\b\s\b([^0-9])/) { "#$1-#$2" }

-- Jim Weirich
--
Posted via http://www.ruby-....

7stud --

11/1/2007 8:11:00 PM

0

Jim Weirich wrote:
> Is this what you want:
>
> str.gsub(/([^0-9])\b\s\b([^0-9])/) { "#$1-#$2" }
>

Or simply:

new_str = str.gsub(/([a-zA-Z]) ([a-zA-Z])/) {"#$1-#$2"}
puts new_str

--output:--
this-is-text-that I want-to 9 9.90 89 9 ii8 u
--
Posted via http://www.ruby-....

7stud --

11/2/2007 1:54:00 AM

0

7stud -- wrote:
> Jim Weirich wrote:
>> Is this what you want:
>>
>> str.gsub(/([^0-9])\b\s\b([^0-9])/) { "#$1-#$2" }
>>
>
> Or simply:
>
> new_str = str.gsub(/([a-zA-Z]) ([a-zA-Z])/) {"#$1-#$2"}
> puts new_str
>
> --output:--
> this-is-text-that I want-to 9 9.90 89 9 ii8 u

You can also write it this way, which I think is even simpler since that
block might be a little confusing:

new_str = str.gsub(/([a-zA-Z]) ([a-zA-Z])/, '\1-\2')


--
Posted via http://www.ruby-....

rfischer

6/19/2011 6:55:00 AM

0

Mr.B1ack <bw@barrk.net> wrote:
>Uncle Uh-huh <moenkopi@comcast.net> wrote:
>
>>Jesus freaks collaborating with international drug cartels and
>>sympathetic politicians could do what Hitler, Tojo, Khruschev, bin
>>Laden failed to do. Ought to be one helluva showdown! Onward
>>Christian soldiers? WOW!
>>http://www.cnsnews.com/news/article/analysis-how-christian-militan...
>
> Socialists are more of a threat. They'll keep borrowing
> more and more trillions, bring us down from within ...

Another rightard lie.

In fact it have been the Republicans who have borrowed trillions of
dollars and have created a $1.5 trillion annual budget deficit.

--
Ray Fischer | Mendocracy (n.) government by lying
rfischer@sonic.net | The new GOP ideal

Blackwater

6/19/2011 7:09:00 AM

0

Bluesfan2U <bluesfan2u@Use-Author-Supplied-Address.invalid> wrote:

>On 6/18/2011 10:04 PM, Mr.B1ack wrote:
>> Uncle Uh-huh<moenkopi@comcast.net> wrote:
>>
>>> Jesus freaks collaborating with international drug cartels and
>>> sympathetic politicians could do what Hitler, Tojo, Khruschev, bin
>>> Laden failed to do. Ought to be one helluva showdown! Onward
>>> Christian soldiers? WOW!
>>> http://www.cnsnews.com/news/article/analysis-how-christian-militan...
>>
>> Socialists are more of a threat. They'll keep borrowing
>> more and more trillions, bring us down from within ...
>>
>It is difficult to fight treason from within. That is why Napolitano is
>still effective for the enemies of America.

Formenting revolution within our creditor nations
is gonna be most effective.


Bluesfan2U

6/19/2011 10:05:00 AM

0

On 6/18/2011 8:04 PM, Mr.B1ack wrote:
> Uncle Uh-huh<moenkopi@comcast.net> wrote:
>
>> Jesus freaks collaborating with international drug cartels and
>> sympathetic politicians could do what Hitler, Tojo, Khruschev, bin
>> Laden failed to do. Ought to be one helluva showdown! Onward
>> Christian soldiers? WOW!
>> http://www.cnsnews.com/news/article/analysis-how-christian-militan...
>
> Socialists are more of a threat. They'll keep borrowing
> more and more trillions, bring us down from within ...
>

That Reagan was the worst of the lot!!!

Bluesfan2U

6/19/2011 10:07:00 AM

0

On 6/19/2011 12:08 AM, Mr.B1ack wrote:
> Bluesfan2U<bluesfan2u@Use-Author-Supplied-Address.invalid> wrote:
>
>> On 6/18/2011 10:04 PM, Mr.B1ack wrote:
>>> Uncle Uh-huh<moenkopi@comcast.net> wrote:
>>>
>>>> Jesus freaks collaborating with international drug cartels and
>>>> sympathetic politicians could do what Hitler, Tojo, Khruschev, bin
>>>> Laden failed to do. Ought to be one helluva showdown! Onward
>>>> Christian soldiers? WOW!
>>>> http://www.cnsnews.com/news/article/analysis-how-christian-militan...
>>>
>>> Socialists are more of a threat. They'll keep borrowing
>>> more and more trillions, bring us down from within ...
>>>
>> It is difficult to fight treason from within. That is why Napolitano is
>> still effective for the enemies of America.
>
> Formenting revolution within our creditor nations
> is gonna be most effective.
>
>

Why bother if you are that despicable? The debts are in US dollars. Just
turn on the presses when you want to pay a bill.

Bluesfan2U

6/19/2011 3:30:00 PM

0

On 6/19/2011 5:04 AM, Bluesfan2U wrote:
> On 6/18/2011 8:04 PM, Mr.B1ack wrote:
>> Uncle Uh-huh<moenkopi@comcast.net> wrote:
>>
>>> Jesus freaks collaborating with international drug cartels and
>>> sympathetic politicians could do what Hitler, Tojo, Khruschev, bin
>>> Laden failed to do. Ought to be one helluva showdown! Onward
>>> Christian soldiers? WOW!
>>> http://www.cnsnews.com/news/article/analysis-how-christian-militan...
>>>
>>
>> Socialists are more of a threat. They'll keep borrowing
>> more and more trillions, bring us down from within ...
>>
>
> That Reagan was the worst of the lot!!!

He really scared the shit out of the Socialist scum, and almost ended
Communism. He knew how to deal with foreign countries, unlike the
incompetent Obama. Reagan had a foreign policy and domestic policy that
helped build America stronger. It's a shame that our country is being
destroyed by a sleeper agent of Islam.

Bluesfan2U

6/19/2011 5:23:00 PM

0

On 6/19/2011 8:29 AM, Bluesfan2U wrote:
> On 6/19/2011 5:04 AM, Bluesfan2U wrote:
>> On 6/18/2011 8:04 PM, Mr.B1ack wrote:
>>> Uncle Uh-huh<moenkopi@comcast.net> wrote:
>>>
>>>> Jesus freaks collaborating with international drug cartels and
>>>> sympathetic politicians could do what Hitler, Tojo, Khruschev, bin
>>>> Laden failed to do. Ought to be one helluva showdown! Onward
>>>> Christian soldiers? WOW!
>>>> http://www.cnsnews.com/news/article/analysis-how-christian-militan...
>>>>
>>>>
>>>
>>> Socialists are more of a threat. They'll keep borrowing
>>> more and more trillions, bring us down from within ...
>>>
>>
>> That Reagan was the worst of the lot!!!
>
> He really scared the shit out of the Socialist scum, and almost ended
> Communism.

Pope John Paul Dos did that, not Reagan even though he had his chance at
Helsinki.


> He knew how to deal with foreign countries, unlike the
> incompetent Obama. Reagan had a foreign policy and domestic policy that
> helped build America stronger. It's a shame that our country is being
> destroyed by a sleeper agent of Islam.

All Reagan knew how to do was lie to get elected, spend money like a
drunken Republican, and nap on the job.

Blackwater

6/19/2011 10:19:00 PM

0

Bluesfan2U <bluesfan2u@fun.ogr> wrote:

>On 6/19/2011 12:08 AM, Mr.B1ack wrote:
>> Bluesfan2U<bluesfan2u@Use-Author-Supplied-Address.invalid> wrote:
>>
>>> On 6/18/2011 10:04 PM, Mr.B1ack wrote:
>>>> Uncle Uh-huh<moenkopi@comcast.net> wrote:
>>>>
>>>>> Jesus freaks collaborating with international drug cartels and
>>>>> sympathetic politicians could do what Hitler, Tojo, Khruschev, bin
>>>>> Laden failed to do. Ought to be one helluva showdown! Onward
>>>>> Christian soldiers? WOW!
>>>>> http://www.cnsnews.com/news/article/analysis-how-christian-militan...
>>>>
>>>> Socialists are more of a threat. They'll keep borrowing
>>>> more and more trillions, bring us down from within ...
>>>>
>>> It is difficult to fight treason from within. That is why Napolitano is
>>> still effective for the enemies of America.
>>
>> Formenting revolution within our creditor nations
>> is gonna be most effective.
>>
>>
>
>Why bother if you are that despicable? The debts are in US dollars. Just
>turn on the presses when you want to pay a bill.

Heh ... and destroy everybodys savings eh ?

Besides, even if you devalued the currency by
half, it'd STILL be an unpayable amount.

Oh, and the Chinese aren't idiots ... they've
already been adjusting interest rates and such
to make sure they get back their full VALUE -
so even if a dollar becomes worth a dime, we'll
just owe 'em ten times as much. The inflation
trick is DOA.