0

I'm trying to modify a binary string. Problem is that the base of the 1s in the string is variable. So it could be that I have 11 that should become 1, but also 111 to become 1 depending on a timeUnit. The timeUnit is longest consecutive '1's divided by 3 (max symbol length = 3 timeUnits).

I tried to replace the 1s with string.gsub!(/1{timeUnit}+/,"1").

In my test if I hard code a number I get the expected string back but I want it to be dynamic.

Is what I am trying to establish possible?

2
  • 1
    Regexp literals support interpolation in the same way double quoted strings do so I thing you are looking for/1{#{timeUnit}}+/? Commented Jul 9, 2021 at 23:39
  • Does this answer your question? Interpolating a string into a regex Commented Jul 10, 2021 at 9:58

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.