name: portada class: portada-slide, center, middle # Expresions regulars ### Regex .footnote[Joan Puigcerver Ibáñez] --- layout: true class: regular-slide .right[.logo[]] --- # Regex - Defineix un patro de cerca en un text. --- # Tutorial - [https://regexone.com/](https://regexone.com/) - Fes fins a la lliço 10 (inclosa). --- # Regex Java - Podem definir una regex dins d'un string. - Les \ les hem d'espar (\\). - Exemple - Regex: \w - Java: "\\w" --- # Regex Java - Funcions de String ``` boolean matches = string.matches("regex"); String[] split = string.split("regex"); String oneReplaced = string.replaceFirst("regex", "replacement"); String allReplaced = string.replaceAll("regex", "replacement"); ``` --- # Regex Java ``` Pattern pattern = Pattern.compile("\\w+"); // in case you would like to ignore case sensitivity, // you could use this statement: // Pattern pattern = Pattern.compile("\\s+", Pattern.CASE_INSENSITIVE); Matcher matcher = pattern.matcher(EXAMPLE_TEST); // check all occurance while (matcher.find()) { System.out.print("Start index: " + matcher.start()); System.out.print(" End index: " + matcher.end() + " "); System.out.println(matcher.group()); } ```