Jump to content

Regular expression to replace a string in Notepad++


n2n1

Recommended Posts

Who can tell me how to write a regular expression to replace a string in Notepad++?

My task is to increase the all font size by 1 (lines containing font_size="XX")

 

Perhaps this is not enough search/replacement ability, and need a script?

Link to comment
Share on other sites

This will take care of values 0 thru 99

 

find what:

(font_size=")((\d?)0")|((\d?)1")|((\d?)2")|((\d?)3")|((\d?)4")|((\d?)5")|((\d?)6")|((\d?)7")|((\d?)8")|(9")|(19")|(29")|(39")|(49")|(59")|(69")|(79")|(89")|(99")

replace with:

$1(?{2}$3(1)")(?{4}$5(2)")(?{6}$7(3)")(?{8}$9(4)")(?{10}$11(5)")(?{12}$13(6)")(?{14}$15(7)")(?{16}$17(8)")(?{18}$19(9)")(?{20}10")(?{21}20")(?{22}30")(?{23}40")(?{24}50")(?{25}60")(?{26}70")(?{27}80")(?{28}90")(?{29}100")

 

The code boxes are a pain to copy from... sorry about that... but when I place this in plain text and you try to copy from that, the line wrapping can sometimes add spaces into the strings.

Link to comment
Share on other sites

Thank You!

this can be used as is or should i insert the missing values (i noticed that here not the whole series of numbers) ?

 

that is, as i understood, the replacement string does not contain arithmetic operations?

Link to comment
Share on other sites

That can be used as is to increment font sizes 0 thru 99 to 1 thru 100. I stopped there because I rarely see font sizes larger than that in anything. If there is more that you need it to replace, I can help with that. In some cases not just one regex replacement, but a series of them can do the job.

 

Regex can't do math. Notepad can if you load scripts into it. I think it uses Python. If it gets too crazy to do with regex, I recommend that. This regex is pretty much on the border of insanity. In fact, if you tried to find this on the Internet, you probably wouldn't find much similar... it just isn't something you would normally use it for.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...