Mastering Regular Expressions (2nd Edition) [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Mastering Regular Expressions (2nd Edition) [Electronic resources] - نسخه متنی

Jeffrey E. F. Friedl

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید










6.8 In Summary: Think!


I'd like to end this chapter with a story that illustrates just how much benefit a little
thought can go when using NFA regular expressions. Once when using GNU
Emacs, I wanted a regex to find certain kinds of contractions such as "don't," "I'm,"
"we'll," and so on, but to ignore other situations where a single quote might be
next to a word. I came up with a regex to match a word,
\<\w+
, followed by the
Emacs equivalent of
'([tdm]|re|ll|ve)
. It worked, but I realized that using

\<\w+
was silly when I needed only \w. You see, if there is a \w immediately
before the apostrophe, \w+ is certainly there too, so having the regex check for
something we know is there doesn't add any new information unless I want the
exact extent of the match (which I didn't, I merely wanted to get to the area).
Using \w alone made the regex more than 10 times faster.

Yes, a little thought can go a long way. I hope this chapter has given you a little to
think about.


/ 83