如何在正则表达式匹配后选择n个字符(How to select n character after regex match)

编程入门 行业动态 更新时间:2024-10-12 05:51:56
如何在正则表达式匹配后选择n个字符(How to select n character after regex match)

我有网址'http:abc.com/test/test1/123-343$fsdsf$gdgdgfdgfdg35435435'

我想在'http:abc.com/test/test1/'之后选择36个字符我写了正则表达式(?<=http[s]?://abc.com/\w*/\w*/)匹配模式。 问题在于选择器。 我希望在模式匹配后选择下一个36个字符。

我正在尝试(?<=http[s]?://abc.com/\w*/\w*/){36}但它无效。

最大的问题是在模式匹配之后,可能存在少于36个字符。 我也想处理这种情况。 即如果模式匹配后出现的字符小于36,则选择模式匹配后出现的字符数。

I am having url 'http:abc.com/test/test1/123-343$fsdsf$gdgdgfdgfdg35435435'

i want to select 36 characters occur after 'http:abc.com/test/test1/' i had wrote regex (?<=http[s]?://abc.com/\w*/\w*/) which match the pattern. The problem is with selector. i want to select next 36 char after pattern match.

i was trying (?<=http[s]?://abc.com/\w*/\w*/){36} but it is not working.

the big problem is after pattern match there can be less than 36 char present. i want to handle this situation as well. i.e If char present after pattern match are less than 36, then select what ever number of char present after pattern match.

最满意答案

(?<=https?:\/?\/?abc\.com\/[^\/]*\/[^\/]*\/).{1,36}

你可以试试这个。 {1,36}即使小于36也可以捕获角色。

(?<=https?:\/?\/?abc\.com\/[^\/]*\/[^\/]*\/).{1,36}

You can try this.{1,36} will allow to capture character even if it less than 36.

更多推荐

本文发布于:2023-08-03 09:45:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1386260.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   如何在   正则表达式   select   regex

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!