I am working in Jquery
Is it possible to take a fragment from String variable? such as:
var text = "azerty uiop hello qsdf ghjklm wxcvbn";
I want take "hello" with 5 symboles before and after:
uiop Hello qsdf
I am working in Jquery
Is it possible to take a fragment from String variable? such as:
var text = "azerty uiop hello qsdf ghjklm wxcvbn";
I want take "hello" with 5 symboles before and after:
uiop Hello qsdf
This should work:
var text = "azerty uiop hello qsdf ghjklm wxcvbn";
console.log((text.match(/.{0,5}hello.{0,5}/) || [''])[0]); // uiop hello qsdf
{0,5} in case the match is at a position which doesn't have 5 characters before or after.