How to replace patterns and preserve some variable portions?

How to replace patterns and preserve some variable portions?

8
NewbieNewbie
8

    Mar 22, 2006#1

    Sorry I don't even know how to write the subject of my question. And thus don't know how to search possible existing solutions. But here is the case:

    I've many html files in a folder and they contain the pattern:

    <a href="../ch[V1]/[V2].html">

    where [V1] and [V2] varies among the files:
    <a href="../ch01/01-03.html">
    .....
    <a href="../ch12/8.html">
    .....

    I want to change them into the pattern:

    <a href="[V1]_[V2].html">

    Thus
    <a href="../ch01/01-03.html"> becomes
    <a href="01_01-03.html"> and <a href="../ch12/8.html"> becomes
    <a href="12_8.html"> .....

    Is there a way to make such changes by a single replace with UE32?

    Thanks a lot

    [email protected]

    30
    Basic UserBasic User
    30

      Mar 22, 2006#2

      Using perl regex (new in 12.00)

      Code: Select all

      Find:     "../ch([^/]+)/([^.]+)\.html"
      Replace:  "\1_\2.html"
      
      I am not familiar enough with UE style regex to comment on that method.

      6,686585
      Grand MasterGrand Master
      6,686585

        Mar 22, 2006#3

        With Replace In Files with a regular expression. My first one is an UltraEdit style regular expression. First look at Configuration - Searching and make sure that Unix style Regular Expressions or Perl compatible Regular Expressions (UE v12) is not enabled.

        Then open Replace In Files, enable Regular Expressions and enter following:

        Find What: <a href="../ch^(*^)/^(*^).html">
        Replace With: <a href="^1_^2.html">

        See help of UltraEdit for details about regular expressions and an explanation how this works.

        Because it is easy, here is also the Unix style regular expression (not tested):

        Find What: <a href="\.\./ch(.*)/(.*)\.html">
        Replace With: <a href="\1_\2.html">

        8
        NewbieNewbie
        8

          Sep 08, 2011#4

          Thank you very much roland and Mofi. That worked!