TAILIEUCHUNG - Beginning Regular Expressions 2005 phần 10

Trả về một đối tượng MatchCollection có chứa không hoặc nhiều đối tượng trận đấu, trong đó có chứa tất cả các trận đấu (hoặc không có) trong chuỗi là tham số để phương pháp quả các trận đấu (). Thay thế tất cả các lần xuất hiện của một mẫu biểu thức chính quy với một chuỗi ký tự quy định. | Chapter 26 There are also variants in how the print function can be used. It is possible to use the print operator conditionally in the following way. The following code is included in the file in the code download print Enter a string. It will be matched against the pattern Star i . n n chomp my myTestString STDIN The if statement is included in the same line as the print operator after the string to be printed print There is a match for myTestString . if myTestString m Star i The operator in the test for the if statement means There is not a match print There is no match for myTestString . if myTestString m Star i It isn t necessary to express the pattern to match against as a string. You have the option to match against a variable. Matching against a variable is useful when you want to match against the same pattern more than once in your code. Try It Out Matching Against a Variable 1. Type the following code in your chosen editor and save the code as usr bin perl -w use strict my myPattern A d 5 - d 4 print Enter a US Zip Code my myTestString STDIN chomp myTestString print You entered a Zip code. n n if myTestString m myPattern print The value you entered wasn t recognized as a US Zip code. if myTestString m myPattern 2. Run the code in Komodo or at the command line. When prompted enter the test string 12345 and inspect the displayed result. 3. Run the code again F3 if you are using the Windows command line . When prompted enter the test string 12345-6789 and inspect the displayed result. 4. Run the code again. When prompted enter the test string Hello world and inspect the result as shown in Figure 26-14. 3 Command Prompt .n x C xBRegExpxCh26 perl Enter a US Zip Code 12345 ou entered a Zip code. C xBRegExpxCh26 pcrl MatcliUs ingUariable - pl Enter a US Zip Code 12345-6789 Vou entered a Zip code. C BRegExp Ch26 perl Enter a US Zip Code Hello world The ualue you entered .

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.