Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Tham khảo tài liệu 'professional information technology-programming book part 99', 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ả | r n r n 101 Ben Forta 102 Jim James 103 Roberta Robertson 104 Bob Bobson r n matches a carriage return line feed combination used by Windows as an end-of-line marker. Searching for r n r n therefore matches two end-of-line markers and thus the blank line in between two records. Tip I just stated that r n is used by Windows as an end-of-line marker. However Unix and Linux systems use just the linefeed character. On those system you ll probably just want to use n and not r . The ideal regular expression should probably accommodate both an optional r and a required n. You ll revisit this example in the next lesson. You ll likely find frequent uses for r and n as well as t tab . The other whitespace characters tend to be used infrequently. Note You ve now seen a variation of the metacharacter. The . and are metacharacters unless they are escaped. f and n for example are metacharacters only when they are escaped. Left unescaped they are literal characters that match only themselves. Matching Specific Character Types Thus far you have seen how to match specific characters any characters using . one of a set of characters using and and how to negate matches using A . Sets of characters matching one of a set is the most common form of matching and special metacharacters can be used in lieu of commonly used sets. These metacharacters are said to match classes of characters. Class metacharacters are never actually needed you can always enumerate the characters to match or use ranges but you will undoubtedly find them to be incredibly useful. Note The classes listed next are the basics supported in almost all regular expression implementations. Matching Digits and Nondigits As you learned in Lesson 3 0-9 is a shortcut for 0123456789 and is used to match any digit. To match anything other than a digit the set can be negated as A0-9 . Table 4.2 lists the class shortcuts for digits and nondigits. Table 4.2. Digit Metacharacters Metacharacter Description d Any digit same as 0-9