1

I have this huge block of code.

        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_55.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_56.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_57.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_58.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_59.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_60.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_61.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_62.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_63.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_64.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_65.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_66.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_67.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_68.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_69.jpg" media-type="image/jpeg"/>
        <item id="P2_0102_01.jpg" href="images/01_02/P2_0102_70.jpg" media-type="image/jpeg"/>

And what I would like to ask is how to replace all the 01.jpg's with 55, 56, 57, etc with Notepad++. I was informed in chat that it was possible with CTRL+H and regular expressions but I have absolutely no knowledge of regex whatsoever, but I'd like to learn.

So... how is this done? If it's okay, I'd like some explanations too so I can learn something. :)

Willow
  • 153
  • 12

4 Answers4

1

search this : 01(?=\.jpg)(.*)(\d{2}).jpg

replace with : \2\1\2.jpg

demo here : http://regex101.com/r/hP7kC3

aelor
  • 10,892
  • 3
  • 32
  • 48
1

You could replace

id="(.*_)\d+.jpg" href="(.*_(\d+)).jpg"

Regular expression visualization

By

id="\1\3.jpg" href="\2.jpg"
sp00m
  • 47,968
  • 31
  • 142
  • 252
0

Find what: _(\d+)(.jpg.*_)(\d+).jpg

Replace with: _$3$2$3.jpg

Explanation: First define three captures by using (), in which the first is the 01 that you want to replace, the second is the content between 01 and 56...70 and the third is the content that you want to replace with, i.e. 56...70. Then you just need to use the third capture to fill the first one, i.e. _$3$2$3.jpg instead of _$1$2$3.jpg (the original). Done!

herohuyongtao
  • 49,413
  • 29
  • 133
  • 174
0

Search: item id=\".+\" href="(.+)" media Replace: item id="\1" href="\1" media

It will search for a matching string with

item id="{{some characters}}" href="{{some characters}}" media

the second character group (.+) is a matching group what you can use in your replace pattern (that is the first one, so you can reference it as \1

The replace string says that replace the matching string with the given string, where use the first matching group at the given positions \1

Pred
  • 8,789
  • 3
  • 26
  • 46