Professional Information Technology-Programming Book part 104

Tham khảo tài liệu 'professional information technology-programming book part 104', 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ả | Summary The real power of regular expression patterns becomes apparent when working with repeating matches. This lesson introduced match one or more match zero or more match zero or one as ways to perform repeating matches. For greater control intervals may be used to specify the exact number of repetitions as well as minimums and maximums. Quantifiers are greedy and may over match to prevent this from occurring use lazy quantifiers. Lesson 6. Position Matching You ve now learned how to match all sorts of characters in all sorts of combinations and repetitions and in any location within text. However it is sometimes necessary to match at specific locations within a block of text and this requires position matching which is explained in this lesson. Using Boundaries Position matching is used to specify where within a string of text a match should occur. To understand the need for position matching consider the following example The cat scattered his food all over the room. cat The cat scattered his food all over the room. The pattern cat matches all occurrences of cat even cat within the word scattered. This may in fact be the desired outcome but more than likely it is not. If you were performing the search to replace all occurrences of cat with dog you would end up with the following nonsense The dog sdogtered his food all over the room. That brings us to the use of boundaries or special metacharacters used to specify the position or boundary before or after a pattern. Using Word Boundaries The first boundary and one of the most commonly used is the word boundary specified as b. As its name suggests b is used to match the start or end of a word. To demonstrate the use of b here is the previous example again this time with the boundaries specified The cat scattered his food all over the room. bcat b The cat scattered his food all over the room. The word cat has a space before and after it and so it matches bcat b space is one of the characters used to separate words

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
185    333    3    01-06-2024
120    87    4    01-06-2024
128    84    2    01-06-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.