TAILIEUCHUNG - Professional Information Technology-Programming Book part 107

Tham khảo tài liệu 'professional information technology-programming book part 107', công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | The use of subexpressions for grouping is so important that it is worthwhile to look at one more example one not involving repetitions at all. This example attempts to match a year in a user record ID 042 SEX M DOB 1967-08-17 Status Active 19 20 d 2 ID 042 SEX M DOB 1967-08-17 Status Active In this example the pattern was to have located a four-digit year but for greater accuracy the first two digits are explicitly listed as 19 and 20. As explained in Lesson 3 Matching Sets of Characters is the OR operator and so 19 20 matches either 19 or 20 and pattern 19 20 d2 should therefore match any four-digit number beginning with 19 or 20 19 or 20 followed by 2 digits . Obviously this did not work. Why not The operator looks at what is to its left and to its right and reads pattern 19 20 d 2 as either 19 or 20 d 2 thinking that the d 2 is part of the expression that started with 20 . In other words it will match the number 19 or any four-digit year beginning with 20. As such 19 matched. The solution is to group 19 20 as a subexpression as follows ID 042 SEX M DOB 1967-08-17 Status Active 19 20 d 2 ID 042 SEX M DOB 1967-08-17 Status Active With the options all within a subexpression knows that what is wanted is one of the options within the group. 19 20 d 2 thus correctly matches 1967 and would also match any four digits beginning with 19 or 20. At some later date close to a hundred years from now if the code needed to be modified to also match years starting with 21 the pattern could be changed to 19 20 21 d 2 . Although this lesson covers the use of subexpressions for grouping there is another extremely important use for subexpressions. This is covered in Lesson 8 Using Backreferences. Nesting Subexpressions Subexpressions may be nested. In fact subexpressions may be nested within subexpressions nested within subexpressions you get the picture. The capability to nest subexpressions allows for incredibly powerful expressions but it can also make patterns look convoluted .

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.