hankknight
asked on
JavaScript: First Word that Starts with "qu"
Using JavaScript, how can I get the first word in a string that starts with "qu"?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Demo</title>
<script type="text/javascript">
var str='The duck quacked quietly';
alert( first_qu(str) ); // Should be "quacked"
function first_qu(str) {
return str;
}
</script>
</head>
<body>
</body>
</html>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
This works:
function first_qu(str) {
return /qu[^W) ]*/.exec(str);
}
Remove (qu) in the regex, I'm not at my desk ...
ASKER
Open in new window