#1 2022-07-09 16:08

visusys
Member
Registered: 2021-10-16
Posts: 20

Global matching with Regex?

How can I do a global match as outlined here?

For example (simple hypothetical) if I wanted to strip all white space from part of a string:

https://stackoverflow.com/questions/180 … hitespaces

Any help greatly appreciated.

Offline

#2 2022-07-09 19:15

Stefan
Moderator
From: Germany, EU
Registered: 2007-10-23
Posts: 1,161

Re: Global matching with Regex?

FROM:
"    tushar is a good      boy     "
TO:
"tushar is a good boy"

You can use the CleanUp Rule with "Fix spaces"
https://www.den4b.com/wiki/ReNamer:Rules:CleanUp


- - -

If you prefer RegEx:

FROM:
"    tushar is a good      boy     "
TO:
" tushar is a good boy "

You can regex search for "\s\s+" and replace by one single space.

and to get
"tushar is a good boy"
To remove leading and trailing spaces also, additionally search for "^\s+|\s+$" and replace with nothing in an second RegEx rule.
https://www.den4b.com/wiki/ReNamer:Rules:RegEx

- - -

And now altogether with only one RegEx rule:

FROM:
"    tushar is a good      boy     "
TO:
"tushar is a good boy"

Search for "^\s+|\s+$|(\s)\s+" and replace with "$1"

That is  "^\s+  |  \s+$  |  (\s)\s+"





For more complex rules we would use PascalScript.





 


Read the  *WIKI* for HELP + MANUAL + Tips&Tricks.
If ReNamer had helped you, please *DONATE* to Denis or buy a PRO license. (Read *Lite vs Pro*)

Offline

Board footer

Powered by FluxBB