0

string.search(regex)

There any easy way look for and find first occur of a stringin java without using Matcher and Pattern classes. On php and JavaScript exist string.search(regex), there any something like this on Java? Obs: I prefer using regex, but for now is a simple thing that I want, just take last filename (separing by dot), so I'm doing: String get[] = string.toString().split("."); string = get[get.length-1]; Shoud be easier: string = string.search("\\.\w*

quot;);

30th Oct 2020, 10:43 PM
Marcelo Anjos
Marcelo Anjos - avatar
1 Answer
+ 3
I'm not aware of a way to do that without importing regex classes. But you can do this without regex: string = string.substring(string.lastIndexOf("."))
30th Oct 2020, 11:32 PM
Kevin â˜