How to search for a text in a string and return the text if found in JavaScript

2 Answers

0 votes
<script>
var s = "abc xyzzz abc xyz";
document.write(s.match("xyz"));
 
/*
run:
 
xyz  
 
*/
</script>

 



answered Sep 2, 2016 by avibootz
0 votes
<script>
var s = "abc xyzzz abc xyz";
document.write(s.match(/yzz/));
 
/*
run:
 
yzz  
 
*/
</script>

 



answered Sep 2, 2016 by avibootz
...