Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Notepad++ Regular Expression "rounding numbers"

I have this in my SVG file:

d="
m49.84965,40.23129
l99.5682,19.94812
l0.2192,100.11412
l-100.78656,-19.99842
z"

I want to have rounded coordinates:

d="
m50,40
l100,20
l0,100
l-100,-20
z"/>

The entire document is much larger. I used regex to erase the decimals, which are lower then 5:

\.[01234]\d*

But with rounding higher decimals I had much more work:

0\.[56789]\d* ;replace with: 1
1\.[56789]\d* ;replace with: 2
2\. ...

It began to be complicated, when I had to deal with numbers like this one: -19.99842

How do I handle this?

like image 222
Kardaw Avatar asked Jul 05 '26 05:07

Kardaw


1 Answers

Not sure that can be done just in Notepad++, I would use Powershell. That way you can mix regex and numeric functions. Something like this:

gc YourFileName | % {$l = $_; [regex]::Matches($_, '[\d.]+') | % {
$l = $l -Replace $_.Value, ([Int32]$_.Value).ToString()}; $l} | Out-File YourNewFileName
like image 153
Dave Sexton Avatar answered Jul 07 '26 16:07

Dave Sexton



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!