Lesson - 51 : Python Advanced - Python REGEX
**************************************************
Python Core PlayList : https://www.youtube.com/watch?v=_laUbUtzMOs&list=PLxWzQv_1I_ACFomYYjF0HMqmu-w2pyqta
Python Advanced PlayList : https://www.youtube.com/watch?v=RSKv-gSKrpA&list=PLxWzQv_1I_ACjp_DGDwHlTZlndqi4cu0_
**************************************************
Python REGEX:
Regular expression is widely used for pattern matching. Python has built-in support for regular function. To use regular expression you need to import re module.
import re
Now you are ready to use regular expression.
re.search() Method : re.search() is used to find the first match for the pattern in the string.
Syntax: re.search(pattern, string, flags[optional])
re.search() method accepts pattern and string and returns a match object on success orNone if no match is found. match object has group() method which contains the matching text in the string.
All the special character and escape sequences loose their special meanings in raw string so\n is not a newline character, it’s just backslash \ followed by n .
>>> import re
>>> s = "my number is 123"
>>> match = re.search(r'\d\d\d', s)
>>> match
<_sre.SRE_Match object; span=(13, 16), match='123'>
>>> match.group()
'123'
Basic patterns used in regular expression:
Symbol Description
. dot matches any character except newline
\w matches any word character i.e letters, alphanumeric, digits and underscore ( _ )
\W matches non word characters
\d matches a single digit
\D matches a single character that is not a digit
\s matches any white-spaces character like \n, \t, spaces
\S matches single non white space character
[abc] matches single character in the set i.e either match a, b or c
[^abc] match a single character other than a, b and c
[a-z] match a single character in the range a to z.
[a-zA-Z] match a single character in the range a-z or A-Z
[0-9] match a single character in the range 0-9
^ match start at beginning of the string
$ match start at end of the string
+ matches one or more of the preceding character (greedy match).
* matches zero or more of the preceding character (greedy match).
Group capturing
Group capturing allows to extract parts from the matching string. You can create groups using parentheses () . Suppose we want to extract username and host name from the email address in the above example. To do this we need to add () around username and host name like this.
match = re.search(r'([\w.-]+)@([\w.-]+)', s)
Optional flags
Both re.search() and re.findall() accepts and optional parameter called flags. flags are used to modify the behavior of the pattern matching.
Sample Projects : https://github.com/SadaLearningHub1/Python3-Core-And-Advanced-Examples
Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «Lesson - 51 : Python Advanced - Python REGEX», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.
Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.
Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!
Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.