I'm trying to remove some part of a string in order to isolate a value of a sentence.
I would like to store the thing that is liked in a var called thingLoved. So when you type "I love cats" you can have a console.log(thingLoved) = cats
In order do to that, I'm trying to remove I love from the first sentence so it only remains "apples".
In that exemple I can remove love but not i love (because there is a space I guess), I don't know how to do that.
Thanks for the help.
function individuaLetters(e){
e.each(function(){
var letters = $(this).html().replace(/^[a-zA-Z\u00C0-\u017F]+,\s[a-zA-Z\u00C0-\u017F]+$/).toLowerCase();
console.log(letters);
if (letters.includes("i love")) {
var thingLoved = $(this).html().replace("i love","")
console.log(thingLoved);
};
})
}
var text = $('div').find('.indiv');
individuaLetters(text);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div>
<span class="indiv">I love apples</span>
</div>
replace("I love",""), whereIcapitalized, as in the text.