I am trying to execute a block of code on a String if it does not contain only integers. For example, if input is 2017, nothing will happen; else if it's 2017abc, the block of code will be executed.
I have tried the regex ^[0-9]+$
, but it seems like if (!keyword.matches("/^[0-9]+$/")
is not working as I would like it to. I have checked multiple online sources and I'm pretty sure the regex is correct.
Am I missing something here?
Update:
Solved the problem using keywords.replaceAll("\\d", "").length() > 0
. But still not sure why the above doesn't work.
Anyway, thanks to someone who suggested this answer earlier. :)