简体   繁体   English

查找两个字符串之间的所有特定符号

[英]Find all certain symbols between two strings

I need to replace all symbols between two strings.我需要替换两个字符串之间的所有符号。 For example, symbol is < , strings are <code> and </code> .例如,符号是< ,字符串是<code></code> Text example:文本示例:

text <code>template<typename T>...<T></code>

I tried next regex:我尝试了下一个正则表达式:

(<code>[^<]*)<([^\/])

But it finds only first < symbol between <code> (there may be several of them).但它只找到<code>之间的第一个<符号(可能有几个)。 How can i find all symbols?我怎样才能找到所有符号?

You must include the closing </code> in the regular expression to make this work:您必须在正则表达式中包含结束的</code>才能使这项工作:

/<code>(.*)<\/code>/g

You can play around with it here:你可以在这里玩它:
https://regex101.com/r/nHwAHr/1 https://regex101.com/r/nHwAHr/1

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

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