GAS Help with regex.exec()

I’m working on a script to cut down some imported text using a RegEx to find an ending point.

I’ve gotten to the point where I can run my script and I can see the item that I need - but I have no idea how to access this info.

I’ve got a regex.exec() that runs…
3X_d_c_dc944e01cb0a09a856219068f32b43b4fbc1d913.png

How do I access this part?

3X_8_0_8026f1e80b8bab315e031ad9d5d4c3bb66d38890.png

I have tried:

var endPoint = regex.exec(body).index;

  • but that doesn’t work - I get an error.

Thanks so much! 3X_d_6_d69f202e8d434fc9687f315afb983b8204d94feb.gif

Solved Solved
0 8 263
1 ACCEPTED SOLUTION

I think I figured it out.

I was trying to do it all in one shot, as in:

var endPoint = regex.exec(body).index;

The system doesn’t like that, but if you split it up into two parts it works:

var regExRun = regex.exec(body);
var endPoint = regExRun.index;

I’m the type to reduce things to it’s simplest terms if possible; seems that bit me in the ass this time.

View solution in original post

8 REPLIES 8

How so? Something is being output to the endPoint variable? What is it?

See screen shot with big red arrow (^_^)

That’s a screenshot from the debug window where I stopped it right after that variable was set.

  • When I dig into what’s inside the endPoint variable, I see it’s an array (with two entries) - that also had an index.

I need the index value - that’s the character number of where the regex was found.

  • But I have no idea how to extract that value.

So endPoint = “Index: 4123” ?

That’s what I’d like to end up with… how do I get it from a regex array result - when It’s not part of the array.

Have you tried:

regex.exec(body).endpoint.index

It would seem to me to that endpoint is another level array and then index.

FYI this did not work:

3X_e_e_ee3fa09e6ae55128b32eddaf7c9d428bbbe3fe46.png

Thanks. I did not consider the Run part. I usually don’t work with regex much.

I think I figured it out.

I was trying to do it all in one shot, as in:

var endPoint = regex.exec(body).index;

The system doesn’t like that, but if you split it up into two parts it works:

var regExRun = regex.exec(body);
var endPoint = regExRun.index;

I’m the type to reduce things to it’s simplest terms if possible; seems that bit me in the ass this time.

Top Labels in this Space