Last active
August 29, 2025 14:39
-
-
Save sunmeat/5f7d5c9f930a9f23975f to your computer and use it in GitHub Desktop.
regex first example
This file contains hidden or 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 Program { | |
| public static void main(String[] args) { | |
| String text = "Бла бла бла... Сьогодні курс долара складає 41.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