【问题标题】:pasting lines in notepad++ with slight variation in them using regex使用正则表达式在记事本++中粘贴行略有变化
【发布时间】:2021-10-10 09:58:21
【问题描述】:

我有一个要在 SQL 中运行的查询:
select empid, empname from emp_00
但问题是员工的详细信息在一百个表中,其名称范围从 emp_00 到 emp_99 即。 emp_00 , emp_01, emp_02 .... emp_99.

我想使用查询获取所有员工的信息:

select empid, empname from emp_00 union
select empid, empname from emp_01 union
select empid, empname from emp_02 union
.
.
.
select empid, empname from emp_99 

有没有什么方法可以在 notepad++ 中进行整个查询(可能使用正则表达式),因为我的原始查询比这要大一些,手动执行会很困难。

【问题讨论】:

    标签: regex notepad++ text-editor


    【解决方案1】:

    正则表达式的棘手部分是对员工 ID 进行零填充。
    谢天谢地,这是一个非常短的 Python 代码:

    nb_employee = 999
    padding_len = len(str(nb_employee))
    for i in range(nb_employee + 1):
        print(f"select empid, empname from emp_%s union"%(str(i).zfill(padding_len)))
    

    它是否达到了您的预期?

    编辑:如果你没有 python,你可以在那里在线运行它:https://www.online-python.com/8q0ksUagwb

    【讨论】:

    • 非常感谢@Tranbi。这种方法立即解决了我的问题。
    猜你喜欢
    • 2018-05-18
    • 2018-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-03
    • 2016-05-18
    相关资源
    最近更新 更多