Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Matching 2 segments but not 3 segments path in Intent Filter / PatternMatcher.PATTERN_SIMPLE_GLOB

I'm having a problem where I need to filter out "longer" path to not be captured by intent filter.

As printed out in the code below,

    PatternMatcher pm = new PatternMatcher("/..*/..*", PatternMatcher.PATTERN_SIMPLE_GLOB);
    Boolean b = pm.match("/segment/segment");
    Boolean c = pm.match("/segment/segment/segment");

    AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
    alertDialog.setTitle("Alert");
    alertDialog.setMessage(b.toString() + ',' + c.toString());

It shows true,true as the result.

Is there any way to make the result as true,false? Changing the regex to /..*/..*/ and url to /segment/segment/ is impossible.

Thank you. I appreciate discussions

like image 1000
Willy Pt Avatar asked Nov 08 '22 09:11

Willy Pt


1 Answers

^([/][A-Za-z0-9\s!@#$%^&()';{}\[\]=+\-_~`.\\]+){2}

You can use this regular expression to make the result as true, false if there is one, three more segments

View Explanation

like image 194
Arpan Sarkar Avatar answered Nov 15 '22 11:11

Arpan Sarkar