Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e8b89a9

Browse files
author
Amogh Singhal
authored
Update Python_Programming_Quiz.md
1 parent 691811d commit e8b89a9

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

‎Python_Programming_Quiz.md‎

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,17 @@ c.7
519519

520520
For our purpose, we will use the `search()` function, and then use `group()` to get the output.
521521

522+
`search()` will scan through a string, looking for any location where this `re` matches. It returns __None__ if no match is found. <br>
523+
__Syntax:__ `search(pattern, string)`<br>
524+
525+
`group()` will return the match found in `search()`. Defaults to first match<br>
526+
__Syntax:__ `group(index)`
527+
`# group() and group(0) will give the same output` <br>
528+
In case there are multiple matches found, they can be retrieved using `group(index)` where __index__ starts from `0` <br>
529+
To access all the matches as a tuple, use `groups()` function.
530+
531+
`.` is a wild card which will __match any character except newline__
532+
522533
```
523534
>>> import re
524535
>>> rhyme=re.search('.ake','I would make a cake, but I hate to bake')
@@ -528,6 +539,14 @@ For our purpose, we will use the `search()` function, and then use `group()` to
528539

529540
#### 32. Write a regular expression that will accept an email id. Use the re module.
530541

542+
`.` is a wild card which will __match any character except newline__ <br>
543+
`[0-9a-zA-Z]+` Any character of character class `0-9` or `a-z` or `A-Z` any number of times <br>
544+
`\` is used to escape a special character, in this case `.` <br>
545+
`()` is used to specify a group and `|` stands for __or__ <br>
546+
`$` is end of the string <br>
547+
548+
Reference: [Regular Expressions Cheat Sheet](debuggex.com/cheatsheet/regex/python)
549+
531550
```
532551
>>> import re
533552
>>> e=re.search(r'[0-9a-zA-Z.]+@[a-zA-Z]+\.(com|co\.in)$','abc@gmail.com')

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /