简体   繁体   English

使用正则表达式从 URls 中提取值

[英]Extract values from URls using regular expression

I have the following Pattern我有以下Pattern

http://abc.com/#!/[0-9a-z]
http://abc.com/#!/search/%23[^.]

So the first pattern identify the URL of a user and second URL identifies search parameters.因此,第一个模式识别用户的 URL 和第二个 URL 识别搜索参数。

I can check whether the pattern belongs to user or search query using Pattern and Matcher class in Java.我可以使用 Java 中的PatternMatcher class 检查模式是否属于用户或搜索查询。 How can i extract the values of user or search term?如何提取用户或搜索词的值?

You should use capturing group.您应该使用捕获组。 Look at Java regular expressions: capturing groups for details.查看Java 正则表达式:捕获组了解详情。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM