Find and replace numbers between a number range

Find and replace numbers between a number range

9
NewbieNewbie
9

    Apr 30, 2011#1

    Hi!

    I want the javascript or regular expression code for following issue.

    ***********
    find 1 to 15
    And replace with
    <a href="part1.html#page_1">1</a>
    <a href="part1.html#page_13">13</a>
    ***********

    Another one

    ********
    find 16 to 29
    and replace with
    <a href="part2.html#page_18">18</a>
    <a href="part2.html#page_28">28</a>
    **********

    try to understand the above mentioned issue.
    Thanks in advance

    6,687587
    Grand MasterGrand Master
    6,687587

      Apr 30, 2011#2

      For 1 to 15 use the Perl regular expression searching for \<([1-9]|1[0-5])\> and using <a href="part1.html#page_\1">\1</a> as replace string.

      For 16 to 29 the replace string is the same, but the search string is \<(1[6-9]|2[0-9])\>

      And in case you want to search for 13 to 71, the search string would be \<(1[3-9]|[2-6][0-9]|7[01])\>

      9
      NewbieNewbie
      9

        May 19, 2011#3

        Thank you for your reply

        and once more coding needed

        find the numbers between 1-160.

        please reply to this.

        6,687587
        Grand MasterGrand Master
        6,687587

          May 19, 2011#4

          Search string for 1 - 160 (without leading zeros) is: \<([1-9][0-9]{0,1}|1[0-5][0-9]|160)\>

          9
          NewbieNewbie
          9

            Jun 08, 2011#5

            Hi!

            I want one more coding for replace with Perl. Need to find 204 to 224

            thanks in advance

            6,687587
            Grand MasterGrand Master
            6,687587

              Jun 08, 2011#6

              Come on, you should have understood already the concept for finding the appropriate expression for a number range.

              The new search string is: \<(20[4-9]|21[0-9]|22[0-4])\>

              \< ... found string must be at beginning of a word

              (...) ... tag the found string for re-use in replace referenced by \1. Also needed for the OR expression inside the round brackets.

              20[4-9] ... find the string "20" and one more character in range '4' to '9'.

              | ... OR

              21[0-9] ... find the string "21" and one more character in range '0' to '9'.

              | ... OR

              22[0-4] ... find the string "22" and one more character in range '0' to '4'.

              \> .. and found string must stop at end of a word.

              \< and \> make sure that not a part of a larger number like for 12185 is found.