简体   繁体   English

正则表达式替换为捕获,但不以字符串结尾

[英]Regex Replace with Capture not ending with String

I need some help 我需要协助

My pattern looks like 我的图案看起来像

/°>(http|\/)([^|<]+?)(?!\.gif|\.jpg|\.mp|\.png|\.jpeg)<°/gi

I have 4 examples for what I try to achieve: 对于要实现的目标,我有4个示例:

°>/w NICK<°     

$1 -> / $ 1-> /
$2 -> w NICK $ 2-> w NICK

°>http://google.de<°

$1 http $2 ://google.de $ 1 http $ 2://google.de

°>/w NICK|/w NICK<°

no matches because of the | 由于|而没有匹配项

°>http://google.de/img.png<°

no matches because of ending with .png 由于以.png结尾而没有匹配项

Now im totally clueless.... iI got the regex for the first 3 examples working, but can't get the lookahead for ending with a img extension in c# i got it working but not for javascript 现在我完全不知道了。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。。

Use 采用

°>(http|\/)(?![^|<]*\.(?:gif|jpe?g|mp|png)<)([^|<]+)<°

See the regex demo 正则表达式演示

Details : 详细资料

  • °> - a literal substring °> -文字子字符串
  • (http|\\/) - Group 1: http or / (http|\\/) -第1组: http/
  • (?![^|<]*\\.(?:gif|jpe?g|mp|png)<) - a negative lookahead that fails the match if, immediately after http or / , there are 0+ chars other than | (?![^|<]*\\.(?:gif|jpe?g|mp|png)<) -失败比赛如果,之后立即负先行http/ ,还有比其他0+字符| and < followed with some extensions specified in the non-capturing group that are followed with < <后跟非捕获组中指定的某些扩展名,后跟<
  • ([^|<]+) - Group 2 matching 1 or more chars other than | ([^|<]+) -组2匹配1个或多个除|以外的字符 and < <
  • - a literal substring. -文字子字符串。

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

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