How to Adjust Angular's URL matching pattern

て烟熏妆下的殇ゞ 提交于 2019-12-08 19:56:33

See Mozilla Regular Expressions doc: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions

What @shaunhusain already explained in a comment is mostly correct, except for the following:

  • \w matches a single alphanumeric character or underscore
  • + matches 1 or more (not 0 or 1) of the previous character

Therefore, \w+ matches a word of length 1 or more characters.

You do need to modify the regex to only have one slash after the colon if you want to match something like app:/.

Mark's answer is correct, here is what the altered Angular code looks like:

//** CHANGED REGEX TO MATCH ON 'app:/' as well
var SERVER_MATCH = /^([^:]+):\/+(\w+:{0,1}\w*@)?(\{?[\w\.-]*\}?)(:([0-9]+))?(\/[^\?#]*)?      (\?([^#]*))?(#(.*))?$/, //var SERVER_MATCH = /^([^:]+):\/\/(\w+:{0,1}\w*@)?(\{?[\w\.-]*\}?)(:([0-9]+))?(\/[^\?#]*)?(\?([^#]*))?(#(.*))?$/,

I found it on line 5612 or thereabouts. Caveat: I have no idea if there will be deleterious side effects of making this change. The general idea was simply to get angular to match on app:/ as it would http:// so that it could function as an Air app.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!