const regex = /"subscription":."id":.*?,"code":null,/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('"subscription":."id":.*?,"code":null,', 'gm')
const str = `{"event":{"type":"bill_paid","created_at":"2020-11-04T10:41:07.217-03:00","data":{"bill":{"id":90379582,"code":null,"amount":"149.9","installments":1,"status":"paid","seen_at":null,"billing_at":null,"due_at":"2020-11-04T23:59:59.000-03:00","url":"https://app.vindi.com.br/customer/bills/90379582?token=539caa15-8047-4cda-97eb-705eae360eb5","created_at":"2020-11-03T09:07:29.000-03:00","updated_at":"2020-11-04T10:40:54.000-03:00","bill_items":[{"id":108933087,"amount":"149.9","quantity":1,"pricing_range_id":null,"description":null,"pricing_schema":{"id":14598836,"short_format":"R\$ 149,90","price":"149.9","minimum_price":null,"schema_type":"flat","pricing_ranges":[],"created_at":"2020-09-15T09:44:46.000-03:00"},"product":{"id":441371,"name":"Assinatura Anual FD","code":null},"product_item":{"id":17944794,"product":{"id":441371,"name":"Assinatura Anual FD","code":null}},"discount":null}],"charges":[{"id":88993071,"amount":"149.9","status":"paid","due_at":"2020-11-04T23:59:59.000-03:00","paid_at":"2020-11-03T00:00:00.000-03:00","installments":1,"attempt_count":1,"next_attempt":null,"print_url":"https://app.vindi.com.br/customer/charges/88993071?b=90379582\\u0026m=36495\\u0026t=539caa15-8047-4cda-97eb-705eae360eb5","created_at":"2020-11-03T09:07:29.000-03:00","updated_at":"2020-11-04T10:40:54.000-03:00","last_transaction":{"id":153906169,"transaction_type":"charge","status":"success","amount":"149.9","installments":1,"gateway_message":"Boleto emitido","gateway_response_code":"0","gateway_authorization":"6631","gateway_transaction_id":"11fc7cfb-8daf-4812-8fbf-8c621978d68a","gateway_response_fields":{"credit_at":"2020-11-04T00:00:00.000-03:00","due_date":"2020-11-04"},"fraud_detector_score":null,"fraud_detector_status":null,"fraud_detector_id":null,"created_at":"2020-11-03T09:07:29.000-03:00","gateway":{"id":33407,"connector":"itau"},"payment_profile":null},"payment_method":{"id":36495,"public_name":"Boleto bancário online","name":"Boleto WebService Itaú","code":"online_bank_slip","type":"PaymentMethod::OnlineBankSlip"}}],"customer":{"id":17091194,"name":"Marcio Holanda","email":"maholfer@icloud.com","code":null},"period":{"id":48284238,"billing_at":"2020-11-03T00:00:00.000-03:00","cycle":1,"start_at":"2020-11-03T00:00:00.000-03:00","end_at":"2021-11-02T23:59:59.000-03:00","duration":31535999},"subscription":{"id":13081195,"code":null,"plan":{"id":102129,"name":"Assinatura Anual FD - RECORRÊNCIA","code":null},"customer":{"id":17091194,"name":"Marcio Holanda","email":"maholfer@icloud.com","code":null}},"metadata":{},"payment_profile":null,"payment_condition":null}}}}`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions