Answered
I'm trying to create a Regular Expression which will search specific fields (ex. Text65.1 - Text65.20) in order from bottom to top. What I want it to do is find the first field with one set of characters then a space and then another set of charcters. /[az-AZ]+ [az-AZ]/
Then I want it to convert first name (charcters sets) found into an email address by replacing the "" with a "." and adding "@company.com" after the second set of characters. Would I use the .replace(/ /g,'.') for this? Or would I have the expression create a variable and then write script to edit the variable?
Is this even possible or am I on the wrong track?
// Define regular expression for
// the beginning of the string
// followed by one or more word characters
// followed by a space
// followed by one or more word characters
// followed by the end of the string
var re =/^\w+\s\w+$/;
// Here are some possible inputs
var s1 = "Jimmy Buffett";
//var s1 = "James D. Buffett";
//var s1 = "James Delaney Buffett";
//var s1 = "Bubba";
// If we have a match, replace the space
// with a period and add the @domain
if (s1.match(re)) {
s2 = s1.replace(/\s/, ".") + "@margaritaville.edu";
app.alert(s2);
} else {
app.alert("No match, sorry");
}
Test the various strings to see what you get. You may need a more sophisticated match or replace regular expression, but this should get you started.
George