// Regex that we want to search in the page source:
var regex = /DOCTYPE [a-zA-Z]+/;
var result = String(context.getDriver().getPageSource()).match(regex);
// save the result to the user state variable "foo"
The result will be a user state variable "foo" set to the DOCTYPE string of the document (not particularly useful, but you can change the regex to something meaningful to you). You can then apply the value using any "User Variable" datasource, or in another scripted action by calling getVariable('foo') on the user state. There's no way to test the script except to just run it.
Note: generally, in a real browser testcase, extracting a user state variable is equivalent to asking your human user to memorize and later type back to you some value they see on the screen. In most cases, you will never need to extract any value from a real browser testcase.
Note also: Load Tester also has the ability to extract the text of an element located using the capabilities of the GUI editor. Use an "Extract a value" step to create such an extractor.