Search This Blog

2024/03/23

Javascript Regular Expression:Non Capturing Group Example

Here we have given below text

USD 100 USD 350 USD 345.56 USD currency USD rate

we need to find all numbers preeceded by USD

var line ="USD 100 USD 350 USD 345.56 USD currency USD rate"

var pattern=/(?:USD)(\s\d+\.{0,}\d+)/gm

while(pattern.test(line)){
console.log(RegExp.$1)
}


Output:
100
350
345.56

No comments:

Post a Comment