• If you have a mod, tool or prefab, please use the Resources section. Click Mods at the top of the forums.

Regular expression to replace a string in Notepad++

n2n1

Surviver
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?

 
Last edited by a moderator:
This will take care of values 0 thru 99

find what:

Code:
(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:

Code:
$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.

 
Last edited by a moderator:
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?

 
Last edited by a moderator:
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.

 
Last edited by a moderator:
Back
Top