Replace a very long string with gsub get regexp error

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?

On 15.11.2009 21:44, Ahmad A. 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

Robert K. wrote:

On 15.11.2009 21:44, Ahmad A. 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

Ahmad A. 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

Robert K. wrote:

On 15.11.2009 23:47, Ahmad A. 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

On 15.11.2009 23:47, Ahmad A. 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