代码之家  ›  专栏  ›  技术社区  ›  XDS

记事本++正则表达式查找和替换:匹配但不包括运算符?<=不起作用。为什么?

  •  2
  • XDS  · 技术社区  · 7 年前

    我正在尝试使用记事本++的“查找并替换”对话框来将某个部分全部大写。ssdl文件。我使用的配置如下:

    Regex: (?i)(?<=[<]EntitySet.*?EntityType="Self[.]).*?(?=")
    Replacement Text: \U$1
    

    然而<=表示“匹配但不包括”的运算符似乎不受支持或其他内容。有没有办法让事情顺利进行?我的目标文件是ssdl文件:

    <?xml version="1.0" encoding="utf-8" ?>
    <Schema     Alias="Self"
                Provider="MySql.Data.MySqlClient"
                Namespace="Organotiki.Infrastructure.Core.Store"
                ProviderManifestToken="5.7"
                xmlns="http://schemas.microsoft.com/ado/2009/11/edm/ssdl"
                xmlns:store="http://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator"
                xmlns:customannotation="http://schemas.microsoft.com/ado/2013/11/edm/customannotation">
      <EntityType Name="dbid">
        <Key>
          <PropertyRef Name="DBD_SHORT_NAME" />
        </Key>
        <Property Name="DBD_SHORT_NAME" Type="varchar" MaxLength="10" Nullable="false" />
        <Property Name="DBD_DBTYPE" Type="varchar" MaxLength="1" Nullable="false" />
        <Property Name="DBD_ENCODING" Type="varchar" MaxLength="1" Nullable="false" />
        <Property Name="DBD_INST_DATE" Type="decimal" Precision="8" Scale="0" />
        <Property Name="DBD_VERSION" Type="varchar" MaxLength="50" />
        <Property Name="DBD_LAST_UPDATED" Type="decimal" Precision="8" Scale="0" />
        <Property Name="DBD_VERSION_NR" Type="varchar" MaxLength="20" />
        <Property Name="DBD_SW_VERSION_NR" Type="varchar" MaxLength="20" />
      </EntityType>
      <EntityType Name="gn_setup_vars">
        <Key>
          <PropertyRef Name="GSV_GROUP" />
          <PropertyRef Name="GSV_NAME" />
          <PropertyRef Name="GSV_FROM_DT" />
        </Key>
        <Property Name="GSV_GROUP" Type="varchar" MaxLength="50" Nullable="false" />
        <Property Name="GSV_NAME" Type="varchar" MaxLength="50" Nullable="false" />
        <Property Name="GSV_TYPE" Type="decimal" Precision="4" Scale="0" Nullable="false" />
        <Property Name="GSV_VALUE" Type="varchar" MaxLength="512" Nullable="false" />
        <Property Name="GSV_FROM_DT" Type="decimal" Precision="8" Scale="0" Nullable="false" />
        <Property Name="GSV_TO_DT" Type="decimal" Precision="8" Scale="0" />
        <Property Name="GSV_NOTES" Type="varchar" MaxLength="200" />
      </EntityType>
      <EntityType Name="sequences">
        <Key>
          <PropertyRef Name="SEQ_NAME" />
        </Key>
        <Property Name="SEQ_NAME" Type="varchar" MaxLength="50" Nullable="false" />
        <Property Name="SEQ_NEXT_ID" Type="decimal" Precision="11" Scale="0" Nullable="false" />
        <Property Name="SEQ_INCREMENT" Type="decimal" Precision="2" Scale="0" Nullable="false" />
      </EntityType>
      <EntityType Name="software_properties">
        <Key>
          <PropertyRef Name="SPE_ID" />
        </Key>
        <Property Name="SPE_ID" Type="decimal" Precision="11" Scale="0" Nullable="false" />
        <Property Name="SPE_SFT_CODE" Type="varchar" MaxLength="8" Nullable="false" />
        <Property Name="SPE_NAME" Type="varchar" MaxLength="50" Nullable="false" />
      </EntityType>
      <EntityType Name="sw_user_properties">
        <Key>
          <PropertyRef Name="SUE_ID" />
        </Key>
        <Property Name="SUE_ID" Type="decimal" Precision="11" Scale="0" Nullable="false" />
        <Property Name="SUE_USER_ID" Type="decimal" Precision="11" Scale="0" Nullable="false" />
        <Property Name="SUE_PROPERTY_ID" Type="decimal" Precision="11" Scale="0" Nullable="false" />
      </EntityType>
      <Association Name="SUE_SPE_FK">
        <End Role="software_properties" Type="Self.software_properties" Multiplicity="1" />
        <End Role="sw_user_properties" Type="Self.sw_user_properties" Multiplicity="*" />
        <ReferentialConstraint>
          <Principal Role="software_properties">
            <PropertyRef Name="SPE_ID" />
          </Principal>
          <Dependent Role="sw_user_properties">
            <PropertyRef Name="SUE_PROPERTY_ID" />
          </Dependent>
        </ReferentialConstraint>
      </Association>
      <EntityContainer Name="OrganotikiInfrastructureCoreStoreContainer">
        <EntitySet Name="dbid" EntityType="Self.dbid" Schema="niobe" store:Type="Tables" />
        <EntitySet Name="gn_setup_vars" EntityType="Self.gn_setup_vars" Schema="niobe" store:Type="Tables" />
        <EntitySet Name="sequences" EntityType="Self.sequences" Schema="niobe" store:Type="Tables" />
        <EntitySet Name="software_properties" EntityType="Self.software_properties" Schema="niobe" store:Type="Tables" />
        <EntitySet Name="sw_user_properties" EntityType="Self.sw_user_properties" Schema="niobe" store:Type="Tables" />
        <AssociationSet Name="SUE_SPE_FK" Association="Self.SUE_SPE_FK">
          <End Role="software_properties" EntitySet="software_properties" />
          <End Role="sw_user_properties" EntitySet="sw_user_properties" />
        </AssociationSet>
      </EntityContainer>
    </Schema>
    
    1 回复  |  直到 7 年前
        1
  •  2
  •   Wiktor Stribiżew    7 年前

    NPP使用Boost regex引擎,不支持无限宽度lookbehinds。替换为结构 \K :

    Find:    (?i)<EntitySet[^<]*?EntityType="Self\.\K[^"]+
    Replace: \U$0
    

    详细信息

    • (?i) -不区分大小写的内联修饰符
    • <EntitySet -文字子字符串
    • [^<]*? -任何0个以上字符 < 尽可能少
    • EntityType="Self\. -文字 EntityType="Self. 子字符串
    • \K级 -匹配重置运算符
    • [^"]+ -1个以上字符,除 " (尽可能多)。

    这个 \U 使后面的文本为大写,后面的文本为 $0 ,整个比赛。

    enter image description here