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…
image

How do I access this part?

I have tried:

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

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

Thanks so much!

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

1 Like

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

1 Like

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.

1 Like

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. :rofl:

1 Like

FYI this did not work:

image

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

1 Like