TAILIEUCHUNG - Học php, mysql và javascript - p 39

Regular Expressions Hãy nhìn một chút kỹ hơn các mô hình kết hợp chúng tôi đã làm. Điều này đã được đạt được bằng cách sử dụng biểu thức thông thường, được hỗ trợ bởi cả hai JavaScript và PHP. Họ làm cho nó có thể để xây dựng mạnh mẽ nhất của mô hình thuật toán khớp trong một biểu thức duy nhất. | Figure 17-2. JavaScript form validation in action out into a separate JavaScript file remembering to remove any script or script tags. You could name the file something like and include it right after the initial script section in Example 17-1 using the following statement script src script Regular Expressions Let s look a little more closely at the pattern matching we have been doing. This has been achieved using regular expressions which are supported by both JavaScript and PHP. They make it possible to construct the most powerful of pattern-matching algorithms within a single expression. Matching Through Metacharacters Every regular expression must be enclosed in slashes. Within these slashes certain characters have special meanings there are called metacharacters. For instance an asterisk has a meaning similar to what you have seen if you use a shell or Windows Command prompt but not quite the same . An asterisk means the text you re trying to match may have any number of the preceding character or none at all. For instance let s say you re looking for the name Le Guin and know that someone might spell it with or without a space. Because the text is laid out strangely for instance Regular Expressions 361 someone may have inserted extra spaces to right-justify lines you could have to search for a line such as The difficulty of classifying Le Guin s works So you need to match LeGuin as well as Le and Guin separated by any number of spaces. The solution is to follow a space with an asterisk Le Guin There s a lot more than the name Le Guin in the line but that s OK. As long as the regular expression matches some part of the line the test function returns a true value. What if it s important to make sure the line contains nothing but Le Guin I ll show how to ensure that later. Suppose that you know there is always at least one space. In that case you could use the plus sign because it requires at least one of the preceding

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.