TAILIEUCHUNG - JavaScript Bible, Gold Edition part 117

JavaScript Bible, Gold Edition part 117. This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java applets. | 1008 Part IV JavaScript Core Language Reference character for character. But if you want to do more sophisticated matching for example does the string contain a five-digit ZIP code you d have to cast aside those handy string methods and write some parsing functions. That s the beauty of a regular expression It lets you define a matching substring that has some intelligence about it and can follow guidelines you set as to what should or should not match. The simplest kind of regular expression pattern is the same kind you use in the method. Such a pattern is nothing more than the text that you want to match. In JavaScript one way to create a regular expression is to surround the expression by forward slashes. For example consider the string Oh hello do you want to play Othello in the school play This string and others may be examined by a script whose job it is to turn formal terms into informal ones. Therefore one of its tasks is to replace the word hello with hi. A typical brute force search-and-replace function starts with a simple pattern of the search string. In JavaScript you define a pattern a regular expression by surrounding it with forward slashes. For convenience and readability I usually assign the regular expression to a variable as in the following example var myRegExpression hello In concert with some regular expression or string object methods this pattern matches the string hello wherever that series of letters appears. The problem is that this simple pattern causes problems during the loop that searches and replaces the strings in the example string It finds not only the standalone word hello but also the hello in Othello. Trying to write another brute force routine for this search-and-replace operation that looks only for standalone words would be a nightmare. You can t merely extend the simple pattern to include spaces on either or both sides of hello because there could be punctuation a comma a dash a colon or whatever before or .

TỪ KHÓA LIÊN QUAN
TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.