Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Checking if String ends with something with Java (Regex)

Tags:

java

regex

I need to know whether check whether a String end with something like .xyz plus any characters after it.

Like this:

myString.endsWidth(".css*")

However this does not pass my if-statement. One concrete example is this kind of string: style.css?v=a1b23

Any ideas?

Complete example String:

http://xyz.com//static/css/style.css?v=e9b34
like image 885
quarks Avatar asked Mar 30 '12 13:03

quarks


2 Answers

hum, I am guessing something like this is even better:

return myString.indexOf(".css")>-1;

If you really want to go with regexp, you could use this

return myString.matches(".*?\\.css.*");
like image 196
Guillaume Polet Avatar answered Oct 13 '22 02:10

Guillaume Polet


endsWith takes a string as parameter

matches takes a regular expression

like image 41
Eric C. Avatar answered Oct 13 '22 01:10

Eric C.