EN
JavaScript - get substring by regex
0 points
In this article, we would like to show you how to get substring by regex in JavaScript.
Quick solution:
xxxxxxxxxx
1
const result = text.match(regex);
In this example, we use match()
method with a regular expression to get the 'value'
from the text.
xxxxxxxxxx
1
const text = 'Example value...';
2
const regex = /value/;
3
4
const result = text.match(regex);
5
6
if (result) {
7
console.log(result[0]); // 'value'
8
}