How to match the $ special character using regular expression in Java

1 Answer

0 votes
import java.util.regex.Pattern;
import java.util.regex.Matcher;

public class Main {
    public static void main(String[] args) {
        Pattern pattern = Pattern.compile("\\$");
        String s = "It's only $10.00 today";

        Matcher matcher = pattern.matcher(s);
        boolean match = matcher.find();

        System.out.println(match);
    }
}



/*
run:

true

*/

 



answered Feb 17, 2025 by avibootz

Related questions

...