正则表达式匹配URL子字符串

时间:2021-11-08 15:22:11

I've got what may be a trivial query but I can't seem to get my head around it.

我有一个可能是微不足道的查询,但我似乎无法理解它。

I have some logs which I need to pull certain information from. The logs are in the format (fictional examples):

我有一些日志,我需要从中提取某些信息。日志采用的格式(虚构示例):

www.examplesite.com/user?=/exl/1241374456/in/home
www.examplesite.com/user?=/exl/1228334956/in/home
www.examplesite.com/user?=/exl/1221834456/in/home
www.examplesite.com/user?=/exl/1229934456/in/home

The format is always the same, i.e. /exl/(ten digit identifier)….

格式始终相同,即/ exl /(十位数标识符)....

I was wondering if it is possible to use the .NET regex match to pull this out.

我想知道是否可以使用.NET正则表达式匹配来解决这个问题。

I just can't seem to build a regular expression that works for this. Any ideas or help would be greatly appreciated.

我似乎无法构建一个适用于此的正则表达式。任何想法或帮助将不胜感激。

3 个解决方案

#1


1  

This should mark always: /exl/1241374456

这应该始终标记:/ exl / 1241374456

\/exl\/\d{10}

#2


0  

Well, if it’s going to be the only ten-digit identifier in the string, you can just use [0-9]{10}.

好吧,如果它将成为字符串中唯一的十位数标识符,则可以使用[0-9] {10}。

#3


0  

If you need the ten-digit identifier use this;

如果您需要十位数标识符,请使用此项;

www\.examplesite\.com/user\?=/exl/(?<Number>[0-9]{10})/in/home

Demo here.

and to match the URL of the type you mentioned,use this;

并匹配您提到的类型的URL,使用此;

www\.examplesite\.com/user\?=/exl/[0-9]{10}/in/home

Demo here.

or to keep it simple use this(but please note this ain't going to distinguish between a URL and a simple ten-digit number anywhere in the text)

或者保持简单使用它(但请注意,这不会区分URL和文本中任何地方的简单十位数字)

[\d]{10}

Demo here.

Hope it helps.

希望能帮助到你。

#1


1  

This should mark always: /exl/1241374456

这应该始终标记:/ exl / 1241374456

\/exl\/\d{10}

#2


0  

Well, if it’s going to be the only ten-digit identifier in the string, you can just use [0-9]{10}.

好吧,如果它将成为字符串中唯一的十位数标识符,则可以使用[0-9] {10}。

#3


0  

If you need the ten-digit identifier use this;

如果您需要十位数标识符,请使用此项;

www\.examplesite\.com/user\?=/exl/(?<Number>[0-9]{10})/in/home

Demo here.

and to match the URL of the type you mentioned,use this;

并匹配您提到的类型的URL,使用此;

www\.examplesite\.com/user\?=/exl/[0-9]{10}/in/home

Demo here.

or to keep it simple use this(but please note this ain't going to distinguish between a URL and a simple ten-digit number anywhere in the text)

或者保持简单使用它(但请注意,这不会区分URL和文本中任何地方的简单十位数字)

[\d]{10}

Demo here.

Hope it helps.

希望能帮助到你。