Notepad ++如何按顺序删除包含3个相同字符的行

时间:2018-07-28 11:30:38

标签: regex notepad++

lemme显示示例。我的文件如下:

AaaAab
AacAaa
AacAap
AaaBbb

我想删除在前三个字符中包含三个相同字符的所有行。这意味着我将从以上示例中仅收到AacAap

4 个答案:

答案 0 :(得分:1)

您可以使用类似的内容:

^(?:(.)\1\1.*|.{3}(.)\2\2.*)$

将其放在“查找内容”字段中,然后在“替换为”字段中放置一个空字符串。

这里是Understand the Activity Lifecycle

答案 1 :(得分:0)

  • Ctrl + H
  • 查找内容:^(?:(.)\1\1|...(.)\2\2).*\R
  • 替换为:LEAVE EMPTY
  • UNcheck区分大小写
  • 检查环绕
  • 检查正则表达式
  • 请勿检查. matches newline
  • 全部替换

说明:

^       : beginning of line
(?:     : start non capture group
  (.)   : group 1, any character but newline
  \1\1  : same as group 1, twice
 |      : OR
  ...   : 3 any character
  (.)   : group 2, any character but newline
  \2\2  : same as group 2, twice
)       : end group
.*      : 0 or more any character
\R      : any kind of linebreak

给定示例的结果

AacAap

答案 2 :(得分:0)

您可以使用以下模式:

class EducationPageRouter extends React.Component{
  getInitialState() {
    return {
        opacity: {
        car: 1,
        phone: 1,
      },
    };
  }

  handleMouseEnter(o) {
    const { dataKey } = o;
    const { opacity } = this.state;

    this.setState({
        opacity: { ...opacity, [dataKey]: 0.5 },
    });
  }

  handleMouseLeave(o) {
    const { dataKey } = o;
    const { opacity } = this.state;

    this.setState({
        opacity: { ...opacity, [dataKey]: 1 },
    });
  }

  render() {
    const { opacity } = this.state;

    return (

      <Card>
        <CardContent>
          <Typography variant="title" color="primary" gutterBottom="true">
            Sales Information Display
          </Typography>
          <Typography variant="header1" color="primary" gutterBottom="true">
            Line Graph - Number of Sales to Date Time
          </Typography>
          <Button variant="raised" color="primary">
            Switch
          </Button>

          <ResponsiveContainer width="95%" aspect={9.5/3.8}>
            <LineChart
              data={formattedSales}
              margin={{ top:5, right:10, bottom:5, left:20 }}
            >
              <XAxis
                dataKey="date"
                padding={{ left:0, right:50 }}
                style={{ fontFamily: "Roboto, sans-serif" }}
                tick={{ fontSize: "12.5px"}}
              />
              <YAxis
                dataKey="car"
              />
              <CartesianGrid
                stroke="#f5f5f5"
                strokeDasharray="2.5 2.5"
              />
              <Tooltip
                wrapperStyle={{ fontFamily: "Roboto, sans-serif" }}
              />

              <Legend
                onMouseEnter={this.handleMouseEnter} 
                onMouseLeave={this.handleMouseLeave}
                wrapperStyle={{ fontFamily: "Roboto, sans-serif" }}
                verticalAlign="bottom"
                height={40}
              />

              <Line
                type="monotone"
                dataKey="car"
                stroke="#4169e1"
              />
              <Line
                type="monotone"
                dataKey="phone"
                stroke="#fa8072"
              />
            </LineChart>
          </ResponsiveContainer>
        </CardContent>
      </Card>
    )
  }
}

^(?:...)?(.)\1\1.*\r?\n? 部分将三个连续的相同字符与一个捕获和两个反向引用匹配。 (.)\1\1使前三个字符成为可选字符,这样,连续字符可以位于行首或第4个位置。

{(?:...)?仅在此处匹配该行的所有剩余字符,包括换行符(如果需要,可以保留换行符,只需删除.*\r?\n?

答案 3 :(得分:0)

检查下一个正则表达式(?im)^(?:...)?(.)\1\1.*(?:\R|\z)

要在线尝试正则表达式并获取说明,请单击here

相关问题