0

i have a string "proofs 161798-2 PDF_Review_2.1_Whats_New" I want to find the first digit after the hyphen. however, i am using Enfocus Switch program and does not allow expressions such as (?<=-)/d{1}. It marks the ? and the () red. Does anyone have any suggestions or alternate ways of writing this without using a ? or ()

I tried using /(?<=-)\d{1} using regex 101 generator, and it worked. But after plugging it into Enfocus Switch program, it won't accept it as a valid expression. It states that there is an invalid grouping.

1 Answers1

0

Would a JS solution work? You could try this:

const str = '161798-2 PDF_Review_2.1_Whats_New'
const afterHypen = str.split('-')[1].split('')
const digit = afterHypen.filter(character => !isNaN(Number(character)))[0]

console.log(digit)

OR if the digit will always be the first character after the hyphen then you could even just do this:

const str = '161798-2 PDF_Review_2.1_Whats_New'
const digit = str.split('-')[1][0]

console.log(digit)
Ludolfyn
  • 1,806
  • 14
  • 20