Первый слайд презентации: Regular E xpressions
Студент(а | к и ) 2 ? 41 группы * Розымурадова ?Владлена $
Слайд 2
|What are regular expressions? Regular expressions are a formal language used in computer programs that work with text. They are primarily used for manipulating substrings in text.|
Слайд 4
|They are used by some text editors and utilities for searching and replacing text.| For example, in programs such as Java, PHP, Ruby, Unix utilities.
Слайд 5
|What can be done with regular expressions: * Find all words with a certain root. * Find a specific word and replace it with another. * Find words using logical operations, except for "and".|
Слайд 6
П ример использования именованных обратных ссылок в Python : import re pattern = r"(?P< word >\w+) (?P= word )" text = " Hello Hello " match = re.match ( pattern, text ) if match : print ( match.group (" word ")) # Выводит " Hello "
Слайд 7
Поиск гласных букв: Можно использовать регулярное выражение `[ aeiou ]` для поиска всех гласных букв в слове или тексте. Например, вы можете использовать это выражение для подсчета количества гласных букв в слове: python import re word = "hello" vowels = re.findall ("[ aeiou ]", word) count = len (vowels) print( f"Number of vowels in '{word}': {count}") # Выводит " Number of vowels in 'hello': 2"
Слайд 8
"For example, you can use a regular expression cat to replace all occurrences of the word "cat" with "dog" in the sentence: python import re" sentence = "I have a cat, but my friend has a cat too" new_sentence = re.sub (r"\ bcat \b", "dog", sentence) print( new_sentence ) #OUPTUP " I have a dog, but my friend has a dog too"
Слайд 9
I want to play a little with you. Check how deeply you understood. if the search works by inclusion, I simply will not write the ending, and will still find the desired text : Example. Regex : корабл Output : На корабле И тут корабль У корабля
Слайд 10
what will be output from the this text, if Regex : мебель В России есть свои мебельные заводы и цехи. Но особой популярностью пользуется импортная мебель. Особо хорошо, если верить статистике одного мобильного приложения, дело обстоит с итальянской мебелью.
Слайд 11
Output: мебельные | мебель | мебелью В России есть свои мебельные заводы и цехи. Но особой популярностью пользуется импортная мебель. Особо хорошо, если верить статистике одного мобильного приложения, дело обстоит с итальянской мебелью. Regex : мебель.
Слайд 12
Search for any character. — will find any character (one ). Example. Text: Аня Ася Оля Аля Валя Regex : А.я Output : Аня Ася Аля
Слайд 13
what will be output from the this text, if Regex : К.л К царю пришли якобы на поклон. Но царь был не глуп, и понимал к чему они клонят. Накалилась обстановка. И царь посадил их на кол.
Слайд 14
Output: кол К царю пришли якобы на поклон. Но царь был не глуп, и понимал к чему они клонят. Накалилась обстановка. И царь посадил их на кол. REGEX: К.л
Слайд 15
If we want to find, say, the words “Anna” or “ Alla,” we need to use a range of acceptable values. We put square brackets, and inside them we list the necessary characters: Example. Text: Анна Алла аоикА74арплт Аркан А^&а Абба Regex : А[ нл ][ нл ]а Output : Анна Алла
Слайд 16
what will be output from the this text, if Regex : [ Вв ][ ине ][ лр ] а Вила была пустой, все в ней живущие вышли на улицу, чтобы испытать новую машину. Вера вела машину уверенно. Лева же делал это очень скудно, очень боялся. После этого все выпили вина.
Слайд 17
Output: Вила | Вера Вила была пустой, все в ней живущие вышли на улицу, чтобы испытать новую машину. Вера вела машину уверенно. Лева же делал это очень скудно, очень боялся. После этого все выпили вина. REGEX: [ Вв ][ ине ][ лр ] а
Слайд 19
SOURCES https:// learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference https://chat.openai.com/ https://regexr.com / https://regex101.com / https:// www.regular-expressions.info/ https ://web.telegram.org/a/#- 1001904793841 // «каждому своё» 7. my schizophasia