Java Reference
In-Depth Information
figure 6-10
On the right, you have only the following:
[^<>\r\n]+ specifies that the pattern is one or more of any character, so long as that character is
not a < , > , \r , or \n . This will match plaintext.
After the regular expression definition you have a g , which specifies that this is a global match.
So the <[^>\r\n]+> regular expression will match any start or close tags, such as <p> or </p> . The alternative
pattern is [^<>\r\n]+ , which will match any character pattern that is not an opening or closing tag.
In the following line, you assign the results variable to the Array object returned by the match()
method:
var results = html.match(regex);
The remainder of the code populates a <div/> element with the split HTML:
document.getElementById("output").innerText = results.join("\r\n");
This code uses features you haven't yet seen. It essentially retrieves the element that has an id value of
output ; this is the <div/> element at the top of the body. The innerText property enables you to set
the text inside of the <div/> element. You learn more in later chapters.
You then use the Array object's join() method to join all the array's elements into one string with each
element separated by a \r\n character, so that each tag or piece of text goes on a separate line.
Search WWH ::




Custom Search