Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java Pattern.compile expression - "/login?(\\?.+)?"

Tags:

java

regex

I am trying to understand the regular expression given below:

"/login?(\\?.+)?"

I have gone through the Java docs, but I am not able to clearly understand the purpose of this expression.

I understand that it looks for a string that starts with /login, then after that what does the characters ?(\\?.+)? represent? Please help me in understanding this.

like image 498
Chaitanya Avatar asked Dec 14 '22 21:12

Chaitanya


1 Answers

It optionally matches literal text ?some-text-here after /login. Also /login? makes last n optional:

It matches following inputs:

/logi
/login
/logi?something
/login?something

Regex Demo

like image 164
anubhava Avatar answered Jan 03 '23 23:01

anubhava