如何编写仅针对每行中的第一个匹配项的正则表达式?

问题描述 投票:0回答:1

我想复制一大堆属性,而不是再次将它们全部键入。不过我想避免复制他们的作业。

我尝试的解决方案涉及 VSCode 中的 cmdF 正则表达式。然后选择所有找到的匹配项。 打字稿代码示例。

    this.anchorBillingAddress = this.page.getByTestId('billing-address-section');
    this.anchorShippingAddress = this.page.getByTestId('shipping-address-section');
    this.anchorBilling = this.page.getByTestId('billing-section');
    this.anchorGeneral = this.page.getByTestId('general-section');
    this.anchorStatistics = this.page.getByTestId('statistics-section');

this[^\s]+
这是我尝试过的。然而它最终也会复制作业。如何让它停在每行遇到的第一个空格处?

javascript regex
1个回答
0
投票

您可以使用

\s*\b(this\.[^;]+\s*;)
\s*\b(this\.[^;]+)\s*;
,捕获整条线。

© www.soinside.com 2019 - 2024. All rights reserved.