• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 9. RegExp() > Description

Description

In the simplest form, a regular expression is nothing more than a specific string of text you expect to search for. Without any modifier codes, you could write a regular expression /Hello/ and it would be useful in searching a string for the specific phrase “Hello” (see Listing 9.1).

Listing 9.1. A Sample of Searching Through a String Using Regular Expressions

<?xml version="1.0" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><title></title></head>
<body>
<script language="JavaScript" type="text/javascript">
<!--
var x = "The user has typed 'Hello World' into his computer."
var y = /Hello/

document.write(x.match(y) + "<br>") // displays the string "Hello"
document.write(y.exec(x)) // displays the string "Hello"
//-->
</script>
</body>
</html>


					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint