Войти в систему

Home
    - Создать дневник
    - Написать в дневник
       - Подробный режим

LJ.Rossia.org
    - Новости сайта
    - Общие настройки
    - Sitemap
    - Оплата
    - ljr-fif

Редактировать...
    - Настройки
    - Список друзей
    - Дневник
    - Картинки
    - Пароль
    - Вид дневника

Сообщества

Настроить S2

Помощь
    - Забыли пароль?
    - FAQ
    - Тех. поддержка



Пишет dima_i ([info]dima_i)
@ 2013-05-12 13:35:00


Previous Entry  Add to memories!  Tell a Friend!  Next Entry
URL-matching regex
In case anybody needs it: here is a URL-matching regex, which is a modification of this one (surprisingly, I could not find good solutions on the web, and that was the best one I found). It seemed to have a minor bug, which is hopefully fixed in my version.

in python notation:

urlmatch=re.compile(ur'''(?i)\b(https?:// [^\s()<>]+
(?: \( [^\s()<>]* (?: \( [^\s()<>]* \) [^\s()<>]* )* \) [^\s()<>]*)*
( ( \( [^\s()<>]* (?: \( [^\s()<>]* \) [^\s()<>]* )* \) ) |
[^\s`!()\[\]{};:\'".,<>?\xab\xbb\u201c\u201d\u2018\u2019] ))''', re.X)


It only searches for URLs starting with "http://" or "https://" and with only two levels of nested brackets. If you need a more intelligent regex detecting strings like "www.example.com", you can use the beginning from the original code. Let me know if you find any examples where this regex fails.


(Читать комментарии) - (Добавить комментарий)


[info]dima_i
2013-05-13 00:24 (ссылка)
Just replace "regex" with "C" in your last comment. Of course, you can organize by indentation just the same way you organize any other code.

(Ответить) (Уровень выше)


(Читать комментарии) -