Extract a certain part of a string after a key phrase
javascript, jquery, string
Solution
Try this RegExp :
var str = 'Today is 78 degrees search good weather and sunny in other words a perfect day for search for when does summer end';
var arr = str.split(/ search (for){0,1}/);
alert(arr[arr.length-1]);
Problem
I was wonder the best way one could look for a specific phrase in a string and then take everything after it and store that in a new variable. For example if... ``` var str = 'hello how are you doing the what is a dinosaur search Jim carrey'; ``` Everything after 'search ' or 'search for ', in this case 'Jim carrey' should be stored in a new var— let's call it val. Also, if there are two or more instances of the phrase 'search ' or 'search for ' then only store what is after the latest one in val. For example: if str = 'welcome I am search pie recipie search quick chili recipie' then val would be 'quick chili recipie' Or If str = 'Today is 78 degrees search good weather and sunny in other words a perfect day for search for when does summer end' then val would be 'when does summer end'.