开发者

How to write this reqular expression ? [Get a section from URL]

开发者 https://www.devze.com 2023-03-12 20:42 出处:网络
I have three types of url as below but I just need bold ones. How to get bold ones writing regular expression in php ?

I have three types of url as below but I just need bold ones. How to get bold ones writing regular expression in php ?

page,Home

page,Members.EditProfile

pa开发者_Python百科ge,Members.Seller.Watchlist

Type of a full url:

http://localhost.example:8090/index.php/page,Members.Inbox


What about /.*[,.](.*?)$/?

Usage Example:

$output = preg_match('/.*[,.](.*?)$/', $inputValue, $matches);
echo $matches[1];


Something along

[A-Za-z]+$

Here is a live version (although it's tailored for ruby, I find it helpful for regex debugging in general):

  • http://rubular.com/r/v32oFOiRdo


$part = preg_split('/[,\.]/',$url);
echo $part[count($part)-1];


I'm new to regular expressions, but I am eager. Here is what I got:

\b(?:.+\.|,)+(.+)\b

This should capture the bolded words in group 1.

Hope this helps, ell.


Given a list separated by commas, periods, or a mix of both, this will put the last field in the \1 backreference.

^.*?(?:(?:\.|,).*)*(?:\.|,)(.*?)$

http://rubular.com/r/ewBbSVIeZ6

0

精彩评论

暂无评论...
验证码 换一张
取 消