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

I have a problem when I need to filter out a “longer” path so that it is not captured by the intent filter .

As indicated 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()); 

As a result, it displays true,true .

Is there a way to make the result true,false ? Changing a regex to /..*/..*/ and url to /segment/segment/ not possible.

Thanks. I appreciate the discussion

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

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

Show explanation

+1
source

Source: https://habr.com/ru/post/1275913/


All Articles