I'm trying to catch a person's name. The name would be entered in a text box such as:
my name is Robert or yes my name is Robert etc.
I don't know where the actual name will fall however because of intro words etc.
I was thinking something like this.
- I search for "my name is"
- I capture it in an array
- I split the array
- I now know the actual name follows as such:
namesParts[0]- would be "my"
namesParts[1]- would be "name"
namesParts[2]- would be "is"
namesParts[3]- would be the name i'm looking for.
Something perhaps like the below but this doesn't work.
if (input.search("my name is")!= -1) {
var names = input.match(/my name is/);
var namesParts = names.split(' ');
var one = namesParts[3];
document.result.result.value = "Ok your name is "+one+".";
return true;
}