![](/img/trans.png)
[英]RegEx to find all occurrences of a character not between two other characters
[英]RegEx - How to find all occurrences, including newlines, between two points?
假設我有
changed: true
newTranslated: ''
importedTokens: true
和(注意這里沒有'')
changed: true
newTranslated:
Some cool text here
Here is some more next
importedTokens: true
和
changed: true
newTranslated: '|cFFASD2Hello there!'
importedTokens: true
我想搜索所有內容,包括changed: true 和importedTokens 之間的換行符(這包括changed: true,但不包括importedTokens)。 我也不想匹配newTranslated: ''
使用這個正則表達式,我匹配更改:true 和任何 newTranslated,除了 (NewTranslated: '')。
changed: true\n.*^((?!'').)*$
但只有第一行 newTranslated 它獲取,我希望它繼續運行,直到找到“importedTokens”,但不包含在匹配中
您可以使用帶有捕獲組和負前瞻的模式:
\bchanged:\s*true((?:\n(?!\s*\b(?:newTranslated:\s*''|importTokens:|changed:)).*)*)(?=\n\s*\bimportedTokens:)
模式匹配:
\bchanged:\s*true
匹配單詞changed
然后:
可選空格和 true(
捕獲組 1 (具有您感興趣的數據)
(?:
非捕獲組作為一個整體重復\n
匹配換行符(??\s*\b(::newTranslated:\s*''|importTokens:|changed.)).*)*
如果不包含任何替代項,則匹配整行)
關閉第 1 組(?=\n\s*\bimportedTokens:)
正向前瞻,斷言換行符和importedTokens:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.