Skip to content

Instantly share code, notes, and snippets.

@sunmeat
Last active August 6, 2024 07:05
Show Gist options
  • Save sunmeat/5f7d5c9f930a9f23975f to your computer and use it in GitHub Desktop.
Save sunmeat/5f7d5c9f930a9f23975f to your computer and use it in GitHub Desktop.
regex first example
package com.alex.regex;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class YourClassName {
public static void main(String[] args) {
String text = "Бла бла бла... Сегодня курс доллара составляет 47.97 грн.";
String regex = "\\s\\d+(\\.\\d+)? грн\\.";
Pattern p = Pattern.compile(regex);
Matcher m = p.matcher(text);
if (m.find()) {
System.out.println("I've got it!");
} else {
System.out.println("Oops!");
}
text = m.replaceFirst(" 5 гривен!");
System.out.println(text);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment