I need a regular expression which will match a string only if it doesn’t followed by a forward slash (/) character and I want to match whole string.
For example below string should match
/Raj/details/002-542545-1145457
but not this one
/Raj/details/002-542545-1145457/show
I tried to use Negative Lookahead to achieve this as specified by this answer.
My code is like this.
pattern = Pattern.compile("/.*/details/(?!.*/)");
matcher = pattern.matcher(text);
if(matcher.matches()) {
System.out.println("success");
} else {
System.out.println("failure");
}
It is giving failure. But if I use matcher.find() then it is giving success.
Please help me understanding why it is not matching and a reg-exp to achieve this?
This
will match
but not