Extracting Strings
String validation isn’t the only useful thing you can do with regular expressions. String extraction is also useful; being able to take just part of a string and manipulate it allows you to have more control over the final result. In Script 8.4, we’ll take a list of names entered in first-name-first order and swap them so that they’re in last-name-first order.
To extract strings:
1. | var re = /\s*\n\s*/; |
2. | var nameList = inNameList.split(re); |
Get JavaScript and Ajax for the Web: Visual QuickStart Guide, Seventh Edition now with the O’Reilly learning platform.
O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.