Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.regex.Matcher;
- import java.util.regex.Pattern;
- public class Regex {
- public static void main(String[] args) {
- String schools = "Name: Hillel, City: Odessa; Name: Stanford, City: Stanford";
- // System.out.println(schools.matches(".*__.*"));
- // System.out.println(schools.replaceAll("Name: ([^,]+)", "Name: *$1*"));
- // System.out.println(schools);
- String text = "Hello, my name is\n Robert. I am a programmer.";
- String betterText = text.toLowerCase().replaceAll("[.,!?;:]", "");
- // System.out.println(betterText);
- String[] words = betterText.split("\\s+");
- // for (String w : words) {
- // System.out.println(w);
- // }
- String phoneNumber = "+380975156900";
- Pattern myRegex = Pattern.compile(".{3}(.{3})");
- Matcher m = myRegex.matcher(phoneNumber);
- if (m.find()) {
- System.out.println(m.group());
- } else {
- System.out.println("No carrier code in phone number.");
- }
- }
- }
Add Comment
Please, Sign In to add comment