Tương tác giữa PHP và jQuery - part 33

CHAPTER 9 ■ PERFORMING FORM VALIDATION WITH REGULAR EXPRESSIONS em { background-color: #FF0; border-top: 1px solid #000; border-bottom: 1px solid #000; } Regular Expression Testing In this document, there is a lot of text that can be matched using regex. The benefit of using a regular expression is much more flexible — albeit complex — syntax for text pattern matching. After you get the hang of regular expressions, also called regexes, they will become a powerful tool for pattern matching. TEST_DATA; /* * Use regex to highlight any occurence of the letters. | CHAPTER 9 PERFORMING FORM VALIDATION WITH REGULAR EXPRESSIONS style type text css em background-color FF0 border-top 1px solid 000 border-bottom 1px solid 000 style head body php Store the sample set of text to use for the examples of regex string TEST_DATA h2 Regular Expression Testing h2 p In this document there is a lot of text that can be matched using regex. The benefit of using a regular expression is much more flexible mdash albeit complex mdash syntax for text pattern matching. p p After you get the hang of regular expressions also called regexes they will become a powerful tool for pattern matching. p hr TEST_DATA Use regex to highlight any occurence of the letters a-c pattern a-c i echo preg_replace pattern em 1 em string Output the pattern you just used echo n p Pattern used strong pattern strong p body html After reloading the page you ll see the characters highlighted see Figure 9-5 . You can achieve identical results using abc bac or any other combination of the characters because the class will match any one character from the class. Also because you re using the case-insensitive modifier i you 321 CHAPTER 9 PERFORMING FORM VALIDATION WITH REGULAR EXPRESSIONS don t need to include both uppercase and lowercase versions of the letters. Without the modifier you would need to use A-Ca-c to match either case of the three letters. Figure 9-5. Any character from A-C is highlighted Matching Any Character Except. To match any character except those in a class prefix the character class with a caret A . To highlight any characters except A-C you would use the pattern Aa-c i see Figure 9-6 . Regular Expression Demo O O L http localhost Q Regular Expression Demo h2 Regular Expression 7esting lh2 p In this document there is a lot of text that can be matched using regex. The benefit of using a regular expression is much more flexible rndash albeit complex Arndash syntax for text pattern matching. lp p After you get the hang oj regular expressions also .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
30    257    2    10-05-2024
Đã 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.