i'm having problem when i want to use regexp, i don't know to using 'or' , 'and'. like in if statement.
当我想使用正则表达式时,我遇到问题,我不知道使用'或','和'。喜欢在if语句中。
i'm having url like this
我有这样的网址
http://localhost:85/study/list
and i'm having the words(pattern to regexp) /,/list/top
我有单词(模式到regexp)/,/ list / top
when i try using this
当我尝试使用它
url ="http://localhost:85/study/list";
regexp = RegExp(.*/?/list?/top);
var matches = url.match(regexp);
alert(matches);
and when i change url to http://localhost:85/top
the word of /top not detection but /list is detection . what is wrong?
当我将url更改为http:// localhost:85 / top时/ top未检测到,但/ list是检测。哪里不对?
i wanna to match my words in that url , how i must create regexp for that? please tell me your answer and please give me reference for the regexp i'm newbie thanks for helping...
我想在那个网址中匹配我的话,我必须为此创建正则表达式?请告诉我你的答案,请给我参考regexp我是新手感谢帮助...
3 个解决方案
#1
1
Man, you can test your expressions here RegexPal. It seems that the expression you using havo no effects.
伙计,你可以在这里测试你的表达RegexPal。看来你使用havo的表达没有任何影响。
This expression will match the last sub-directory of your url
此表达式将匹配您网址的最后一个子目录
(\w*)$
For example http://localhost:85/study/list
will match list
, http://localhost:85/top
will match just top
.
例如,http:// localhost:85 / study / list将匹配列表,http:// localhost:85 / top将匹配top。
Try it! =)
尝试一下! =)
#2
1
Put them in parenthesis, such as (/list)?
.
把它们放在括号中,如(/ list)?
#3
1
list? matches lis or list. I think you want (list)?
清单?匹配lis或列表。我想你想要(列表)?
#1
1
Man, you can test your expressions here RegexPal. It seems that the expression you using havo no effects.
伙计,你可以在这里测试你的表达RegexPal。看来你使用havo的表达没有任何影响。
This expression will match the last sub-directory of your url
此表达式将匹配您网址的最后一个子目录
(\w*)$
For example http://localhost:85/study/list
will match list
, http://localhost:85/top
will match just top
.
例如,http:// localhost:85 / study / list将匹配列表,http:// localhost:85 / top将匹配top。
Try it! =)
尝试一下! =)
#2
1
Put them in parenthesis, such as (/list)?
.
把它们放在括号中,如(/ list)?
#3
1
list? matches lis or list. I think you want (list)?
清单?匹配lis或列表。我想你想要(列表)?