NOTA: La traducción de esta documentación es un esfuerzo personal y voluntario, no es un documento oficial de Sun Microsystems ni Oracle ni está patrocinado por ninguna de estas empresas. Los documentos originales (en inglés) están disponibles en: http://java.sun.com/docs/books/tutorial/.
Dirija cualquier comentario, petición, felicitación, etc. a tutorialesjava_@RROBA_codexion.com.
Si desea ayudar a mantener en funcionamiento esta web, colaborar con la traducción de estos documentos o necesita que se traduzca algĂșn capĂ­tulo en concreto puede realizar una donación directa mediante Paypal:
Questions and Exercises: Regular Expressions (The Java™ Tutorials > Essential Classes > Regular Expressions)
Trail: Essential Classes
Lesson: Regular Expressions
Questions and Exercises
Home Page > Essential Classes > Regular Expressions
Questions and Exercises: Regular Expressions

Questions

  1. What are the three public classes in the java.util.regex package? Describe the purpose of each.
  2. Consider the string literal "foo". What is the start index? What is the end index? Explain what these numbers mean.
  3. What is the difference between an ordinary character and a metacharacter? Give an example of each.
  4. How do you force a metacharacter to act like an ordinary character?
  5. What do you call a set of characters enclosed in square brackets? What is it for?
  6. Here are three predefined character classes: \d, \s, and \w. Describe each one, and rewrite it using square brackets.
  7. For each of \d, \s, and \w, write two simple expressions that match the opposite set of characters.
  8. Consider the regular expression (dog){3}. Identify the two subexpressions. What string does the expression match?

Exercises

  1. Use a backreference to write an expression that will match a person's name only if that person's first name and last name are the same.

Check your answers.

Previous page: Additional Resources
Next page: End of Trail