-1
I need to display a text and replace a few words with a field of the type input
. The idea is that it fills in this input
the word that was hidden. It’s like a guessing game.
So let’s assume I have the following text: "Lorem ipsum dolor sit Amet, consectetur adipiscing Elit."
I want to hide the word "ipsum" from this text, causing a field input
appear in her place.
I thought of marking the word using the signs << >>
, this way I could use regex to find these characters, and then replace this content with Jquery. I think the site https://regexr.com/ does just that.
The problem is that I have no idea what kind of regular expression to use to do this. Actually, I don’t even know if that’s possible.
I don’t even have a code approximate to that because I’ve never used regular expressions. The only thing I have so far is this:
var text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.";
var search = "lorem";
var match = search.split(" ").every(function (word) {
var regex = new RegExp(word, "i");
return regex.test(text);
});
if (match) {
alert("String '" + search + "' Encontrada.");
}