Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > replace a very long string with gsub get regexp error

Reply
Thread Tools

replace a very long string with gsub get regexp error

 
 
Ahmad Azizan
Guest
Posts: n/a
 
      11-15-2009
Hello,

I've encountered a problem to replace a very long string with gsub.
The string length is around 80,000.

As example,
data contains string with length 80,000

lala = "Replaced string"

input = input.gsub(data, lala)

Is there any other method for that string replacement like in this case
beside using gsub?
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
 
 
 
Robert Klemme
Guest
Posts: n/a
 
      11-15-2009
On 15.11.2009 21:44, Ahmad Azizan wrote:
> Hello,
>
> I've encountered a problem to replace a very long string with gsub.
> The string length is around 80,000.
>
> As example,
> data contains string with length 80,000
>
> lala = "Replaced string"
>
> input = input.gsub(data, lala)
>
> Is there any other method for that string replacement like in this case
> beside using gsub?


And your problem is?

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
 
 
 
Ahmad Azizan
Guest
Posts: n/a
 
      11-15-2009
Robert Klemme wrote:
> On 15.11.2009 21:44, Ahmad Azizan wrote:
>> input = input.gsub(data, lala)
>>
>> Is there any other method for that string replacement like in this case
>> beside using gsub?

>
> And your problem is?
>
> robert


Sorry for incomplete question.

The problem is that, because of the very long string length, the gsub
return a regexp error indicating that the regular expression is too
long.

Thank you

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

 
Reply With Quote
 
Robert Klemme
Guest
Posts: n/a
 
      11-16-2009
On 15.11.2009 23:47, Ahmad Azizan wrote:
> Robert Klemme wrote:
>> On 15.11.2009 21:44, Ahmad Azizan wrote:
>>> input = input.gsub(data, lala)
>>>
>>> Is there any other method for that string replacement like in this case
>>> beside using gsub?

>> And your problem is?

>
> Sorry for incomplete question.
>
> The problem is that, because of the very long string length, the gsub
> return a regexp error indicating that the regular expression is too
> long.


Ahmad, it's easier for us if you present a complete example along with
the concrete error (e.g. exception with stack trace).

A general remark: it is very uncommon to have a regular expression whose
text is 80k in size. So you probably rather want a different approach
but which one is difficult to tell without having more input.

Kind regards

robert

--
remember.guy do |as, often| as.you_can - without end
http://blog.rubybestpractices.com/
 
Reply With Quote
 
Brian Candler
Guest
Posts: n/a
 
      11-16-2009
Ahmad Azizan wrote:
> lala = "Replaced string"
>
> input = input.gsub(data, lala)
>
> Is there any other method for that string replacement like in this case
> beside using gsub?


Here's one option:

input = "aaaabbbaaaabbbaaaaabbbaaaabbbaaaa"
data = "bb"
lala = "zz"

pos = 0
while pos = input.index(data, pos)
input[pos, data.size] = lala
pos += lala.size
end
--
Posted via http://www.ruby-forum.com/.

 
Reply With Quote
 
Ahmad Azizan
Guest
Posts: n/a
 
      11-17-2009
Robert Klemme wrote:
> On 15.11.2009 23:47, Ahmad Azizan wrote:
>> The problem is that, because of the very long string length, the gsub
>> return a regexp error indicating that the regular expression is too
>> long.

>
> Ahmad, it's easier for us if you present a complete example along with
> the concrete error (e.g. exception with stack trace).
>
> A general remark: it is very uncommon to have a regular expression whose
> text is 80k in size. So you probably rather want a different approach
> but which one is difficult to tell without having more input.
>
> Kind regards
>
> robert


Yup. I know. By showing the code, I just really don' know where to
start.
But after looking at candlerb's option, it is what I really needed, the
starting and ending index of the string really help marking the certain
content in the string.
I can go on from that.
Thanks so much for sharing

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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
[regexp] How to convert string "/regexp/i" to /regexp/i - ? Joao Silva Ruby 16 08-21-2009 05:52 PM
Having compilation error: no match for call to (const __gnu_cxx::hash<long long int>) (const long long int&) veryhotsausage C++ 1 07-04-2008 05:41 PM
gsub and gsub! are inconsistent aurelianito Ruby 9 11-09-2005 01:38 PM
very very very long integer shanx__=|;- C Programming 19 10-19-2004 03:55 PM
very very very long integer Abhishek Jha C Programming 4 10-17-2004 08:19 AM



Advertisments