Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Aprende Group function 1/2 | Regex Wizards (Project)
Regex Wizards (Project)

book
Group function 1/2

The group() function in the re module in Python is used to extract a specific group from a match object returned by methods such as search() or finditer(). A group is created by enclosing a part of the regular expression in parentheses().

Tarea

Swipe to start coding

  1. import re.
  2. Define a text variable as "The cat in the hat.".
  3. Search for the first vowel value in the string using the following grammar: [aeiou].
  4. Print the output using the group() function.

Solución

import re

# Search for a vowel in the text "The cat in the hat"
text = "The cat in the hat"
x = re.search("[aeiou]", text)
print(x.group()) # Output: e

Mark tasks as Completed
¿Todo estuvo claro?

¿Cómo podemos mejorarlo?

¡Gracias por tus comentarios!

Sección 1. Capítulo 5
AVAILABLE TO ULTIMATE ONLY
some-alt