Last active
August 6, 2024 07:05
-
-
Save sunmeat/5f7d5c9f930a9f23975f to your computer and use it in GitHub Desktop.
regex first example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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