正则表达式从整行创建一个组,或者只是给定的标记
Regex to create a group from an entire line, or just up to a given token
我正在使用 JavaScript 正则表达式引擎。
正则表达式 ^(.*?)\s*(?=[*\[]).*
将捕获包含所有字符的组,最多为 [
或 *
字符。它适用于这些行,匹配整行并捕获第一部分:
This should be captured up to here[ but no further]
This should be captured up to this asterisk* but not after it*
但是,如果它不包含这些字符,我也想捕获整行:
This entire line should be captured.
这个正则表达式 ^(.*?)\s*(?=[*\[]).*|^(.*)$
将 匹配 整行,但它不会 捕获 组中的任何内容 </code>.</p>
<p>是否可以修改前瞻以便它也能找到 <code>no more characters
?
只需在正先行断言内添加行锚点的末尾。
^(.*?)\s*(?=[*\[]|$)
您可以使用这个正则表达式:
/^(.*?)\s*(?=[*\[]|[^*\[]$)/
我正在使用 JavaScript 正则表达式引擎。
正则表达式 ^(.*?)\s*(?=[*\[]).*
将捕获包含所有字符的组,最多为 [
或 *
字符。它适用于这些行,匹配整行并捕获第一部分:
This should be captured up to here[ but no further]
This should be captured up to this asterisk* but not after it*
但是,如果它不包含这些字符,我也想捕获整行:
This entire line should be captured.
这个正则表达式 ^(.*?)\s*(?=[*\[]).*|^(.*)$
将 匹配 整行,但它不会 捕获 组中的任何内容 </code>.</p>
<p>是否可以修改前瞻以便它也能找到 <code>no more characters
?
只需在正先行断言内添加行锚点的末尾。
^(.*?)\s*(?=[*\[]|$)
您可以使用这个正则表达式:
/^(.*?)\s*(?=[*\[]|[^*\[]$)/