Hi,
I am using the regex "([0-9]+)" to find all numbers enclosed within quotes. The requirement is to replace the numbers by an equivalent number of spaces ie
"12" -> 4 spaces
"1" -> 3 spaces
"1234" -> 6 spaces
Can this be done?
Thanks in advance,
Aneesh.
Number of characters found by a search expression
Moderators: AmigoJack, bbadmin, helios, Bob Hansen, MudGuard
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
Hi,
The 2 extra spaces are for the quoes enclosing the numbers. I need to replace only those numbers that occur within quotes. The regex i am using is "([0-9]+)" (the quotes are part of the regex). The number of spaces will be 2 more than the number of digits within quotes.
"12" -> 4 spaces (the 2 digits + 2 quotes)
Thanks,
Aneesh.
The 2 extra spaces are for the quoes enclosing the numbers. I need to replace only those numbers that occur within quotes. The regex i am using is "([0-9]+)" (the quotes are part of the regex). The number of spaces will be 2 more than the number of digits within quotes.
"12" -> 4 spaces (the 2 digits + 2 quotes)
Thanks,
Aneesh.
- Bob Hansen
- Posts: 1516
- Joined: Sun Mar 02, 2003 8:15 pm
- Location: Salem, NH
- Contact:
May have to do recursive Search/Replace. But once defined, could be made into a macro.
Example is using "-" to represent a visual representation of invisible spaces
------------------------------------------------------
Search for: "[0-9]{1}"
Replace with: "---"
Search for: "[0-9]{2}"
Replace with: "----"
Search for: "[0-9]{3}"
Replace with: "-----"
...
...
...
Search for: "[0-9]{10}"Replace with: "------------"
Example is using "-" to represent a visual representation of invisible spaces
------------------------------------------------------
Search for: "[0-9]{1}"
Replace with: "---"
Search for: "[0-9]{2}"
Replace with: "----"
Search for: "[0-9]{3}"
Replace with: "-----"
...
...
...
Search for: "[0-9]{10}"Replace with: "------------"
Hope this was helpful.............good luck,
Bob
Bob
-
- Posts: 2461
- Joined: Sun Mar 02, 2003 9:22 pm
You can do it in one go in WildEdit (replace each - with a space):
Note the use of the construct (?:...) instead of (...) at the outer level. This groups the items within it, but doesn't mark them for use in the replacement expression; so they don't interfere with the subexpression numbering that we are about to use.
The replacement expression uses conditional expressions. If the first subexpression within (...) matched, use the parenthesised replacement following ?1; if the second subexpression matched, use the one following ?2; ...
Look for Conditional expressions in the help under Reference | Replacement Format Syntax.
This will find ([0-9]) or ([0-9]){2} or ... within quotes. Extend as required.Find what: "(?:([0-9])|([0-9]){2}|([0-9]){3}|([0-9]){4})"
Replace with: ?1(---):?2(----):?3(-----):?4(------)
[X] Regular expression
[X] Replacement format
Note the use of the construct (?:...) instead of (...) at the outer level. This groups the items within it, but doesn't mark them for use in the replacement expression; so they don't interfere with the subexpression numbering that we are about to use.
The replacement expression uses conditional expressions. If the first subexpression within (...) matched, use the parenthesised replacement following ?1; if the second subexpression matched, use the one following ?2; ...
Look for Conditional expressions in the help under Reference | Replacement Format Syntax.