0

I want to find out if a predefined substring has an additional digit attached. The substring always ends with a digit as well. I wrote some example code that I expected to return a list that contains _B35 but just gives me null:

const changeBlockIdEnding = "_B3"
const paragraph = '_B35';
const regex = changeBlockIdEnding+/[0-9]/;
const found = paragraph.match(regex);

console.log(found); 

when the paragraph contains _B3 it should give me null, when it contains _B3_ it should give me null as well, but when it contains _B35 or any other digit preceding changeBlockIdEnding it should give me a list containing exactly this.

So the big question is, how I include a String-Variable in my regular Expression?

lxg95
  • 379
  • 6
  • 22

0 Answers0