# RegExp test method string length limitation RangeError maximum call stack size exceeded

**URL:** <https://es.discourse.group/t/regexp-test-method-string-length-limitation-rangeerror-maximum-call-stack-size-exceeded/1856>\
**Category:** I have questions\
**Created:** [November 30, 2023, 2:08pm UTC](https://es.discourse.group/t/regexp-test-method-string-length-limitation-rangeerror-maximum-call-stack-size-exceeded/1856 "2023-11-30T14:08:35Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![trir262](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@trir262](https://es.discourse.group/u/trir262)\
**Post date:** [November 30, 2023, 2:08pm UTC](https://es.discourse.group/t/regexp-test-method-string-length-limitation-rangeerror-maximum-call-stack-size-exceeded/1856/1 "2023-11-30T14:08:36Z")

</div>

I stumbled upon a string length limitation for the RegExp test method.  
In fact, when I want to test whether a string is a valid Base64, I use this script.

```javascript
const BASETEST = /^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/gm;
BASETEST.lastIndex = 0;
BASETEST.test(''.padEnd(100,'A'))
// expected output: true

```

This works fine up until a string length of 4473905. When I want to parse a Base64 string that is longer, a RangeError is returned:

```javascript
BASETEST.test(''.padEnd(4473906,'A'))
// returns Uncaught RangeError RangeError: Maximum call stack size exceeded at eval (repl:1:6)

```

Do you agree with me and what would be the way to get this fixed?

This is my very first topic in this group so please be patient with me.  
Regards,

---

<div class="post-metadata">

**Author:** ![ljharb](https://yyz2.discourse-cdn.com/free1/user_avatar/es.discourse.group/ljharb/32/8_2.png) [@ljharb](https://es.discourse.group/u/ljharb)\
**Post date:** [November 30, 2023, 5:17pm UTC](https://es.discourse.group/t/regexp-test-method-string-length-limitation-rangeerror-maximum-call-stack-size-exceeded/1856/2 "2023-11-30T17:17:52Z")

</div>

is there a reason not to just, try to decode it using `atob`?

---

<div class="post-metadata">

**Author:** ![trir262](https://avatars.discourse-cdn.com/v4/letter/t/7cd45c/32.png) [@trir262](https://es.discourse.group/u/trir262)\
**Post date:** [November 30, 2023, 10:33pm UTC](https://es.discourse.group/t/regexp-test-method-string-length-limitation-rangeerror-maximum-call-stack-size-exceeded/1856/3 "2023-11-30T22:33:33Z")

</div>

Thanks for the reply!

`atob` will definitely work in this scenario and I will also use it.

However in a different situation I want to make sure that RegExp does not cause the same issue on larger strings (text files).
