replace a very long string with gsub get regexp error

A

Ahmad Azizan

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?
 
R

Robert Klemme

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
 
A

Ahmad Azizan

Robert said:
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
 
R

Robert Klemme

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
 
B

Brian Candler

Ahmad said:
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
 
A

Ahmad Azizan

Robert said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,817
Latest member
DicWeils

Latest Threads

Top