tailieunhanh - Beginning Regular Expressions 2005 phần 2

Hãy thử các dây từ . Bạn cũng có thể tạo ra chuỗi thử nghiệm của riêng của bạn. Chú ý rằng mô hình \ d \ d \ d sẽ phù hợp với bất kỳ thứ tự của ba chữ số số liên tiếp, nhưng một con số số hoặc cặp của các chữ số số không phù hợp. | Simple Regular Expressions Figure 3-7 shows the result after entering the string Part Number RRG417. Figure 3-7 Try each of the strings from . You can also create your own test string. Notice that the pattern d d d will match any sequence of three successive numeric digits but single numeric digits or pairs of numeric digits are not matched. How It Works The regular expression engine looks for a numeric digit. If the first character that it tests is not a numeric digit it moves one character through the test string and then tests whether that character matches a numeric digit. If not it moves one character further and tests again. If a match is found for the first occurrence of d the regular expression engine tests if the next character is also a numeric digit. If that matches a third character is tested to determine if it matches the d metacharacter for a numeric digit. If three successive characters are each a numeric digit there is a match for the regular expression pattern d d d. You can see this matching process in action by using the Komodo Regular Expressions Toolkit. Open the Komodo Regular Expression Toolkit and clear any existing regular expression and test string. Enter the test string A234BC then in the area for the regular expression pattern enter the pattern d. You will see that the first numeric digit 2 is highlighted as a match. Add a second d to the regular expression area and you will see that 23 is highlighted as a match. Finally add a third d to give a final regular expression pattern d d d and you will see that 234 is highlighted as a match. See Figure 3-8. You can try this with other test text from . I suggest that you also try this out with your own test text that includes numeric digits and see which test strings match. You may find that you need to add a space character after the test string for matching to work correctly in the Komodo Regular Expression Toolkit. Why did we use JavaScript for the preceding example .

crossorigin="anonymous">
Đã 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.