如何在regex匹配后选择n个字符

时间:2021-07-05 20:13:19

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

我有url 'http:abc.com/ test1/123-343$fsdsf$ gdgdgdgfdg35435435 '

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.

我想选择在“http:abc.com/test/test1/”之后出现的36个字符,这些字符与模式匹配。问题是选择器。我想要选择下一个36字符后的模式匹配。

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

我在(? < = http(s)?:/ /abc.com/ \ w * / \ w * /){ 36 }但是它不工作。

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.

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

1 个解决方案

#1


1  

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

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

你可以试试这个。{1,36}将允许捕获字符,即使它小于36。

#1


1  

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

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

你可以试试这个。{1,36}将允许捕获字符,即使它小于36。