1

In this answer: To exceed the ImportXML limit on Google Spreadsheet

How would I match an nth occurrence? I tried including {5} in the script but it would give me an #ERROR!

This site doesn't exactly work with the author's example. https://regex101.com/r/pzMw0A/3

The answer from the author >(.*?%\s+APR) only matches the first occurrence.

What I'm trying to do is to get 2.49% from this page https://actorsfcu.com/loans/auto

Here is the google spreadsheet with the script loaded (A1 & A3): https://docs.google.com/spreadsheets/d/1D6Qf44kL6_x7Ippsj6OkePO_eDBVxkIsHr0iieI0ECY/edit?usp=sharing

sojim
  • 492
  • 2
  • 6
  • 19
  • 1
    try use the `g`flag to make it global and catch all occurences. Now if you wan't to use regex [here](https://github.com/google/re2) is the regex version that uses google – JSmith Sep 09 '18 at 15:55

1 Answers1

1

I would do something like this:

var value = html.match(new RegExp(/>(.*?%\s+APR)/, 'g')[indexOfValue];

put gas indicator argument, this flag will apply the regex even if a new line character occurs.

JSmith
  • 4,519
  • 4
  • 29
  • 45
  • btw, looks like `=importRegex("https://actorsfcu.com/loans/auto",">(.*?%)\s+APR",3)` results in `>1.99% APR` I tried to just get the number from this result, it worked with the previous script but not with this change, do you know why? – sojim Sep 09 '18 at 16:41
  • 1
    I'll check and get back to you if I find the answer – JSmith Sep 09 '18 at 16:55
  • @sojim Well it's normal to get that result what di you wanted `1,99`? – JSmith Sep 09 '18 at 17:12
  • 1
    I got it with this, thank you! `\d\.(.*?%)(?=\s+APR)` – sojim Sep 09 '18 at 17:36