Putting numbers in parentheses



  • Hello,
    I’d like to request a bit of help with the following.

    I have a file with only number combinations. Sometimes I have multiple combinations per line and the combos are separated by semi-colons.

    Sample of the file:

    4 2 1 5
    3 3 0 4
    10 7 12 4
    0 0 0 6
    0 2 3 1; 3 7 9 9; 4 11 12 4
    2 3 3 6; 8 17 1 0
    3 0 0 0
    12 12 15 7; 3 3 6 9; 21 5 2 8; 0 1 0 1
    3 5 5 7; 9 12 3 4
    2 5 8 1
    3 4 7 2

    I’d like to modify it so that every number will be placed inside brackets.

    It should be displayed as:

    (4) (2) (1) (5)
    (3 (3) (0) (4)
    (10 (7) (12) (4)
    (0) (0) (0) (6)
    (0) (2) (3) (1); (3) (7) (9) (9); (4) (11) (12) (4)
    (2 (3) (3) (6); (8) (17) (1) (0)
    (3 (0) (0) (0)
    (12) (12) (15) (7); (3) (3) (6) (9); (21) (5) (2) (8); (0) (1) (0) (1)
    (3) (5) (5) (7); (9) (12) (3) (4)
    (2) (5) (8) (1)
    (3) (4) (7) (2)

    How can I achieve this?

    Thank you,
    Viktória



  • @Viktoria-Ontapado

    Use:

    Find-what zone: (\d+)
    Replace-with zone: \(\1\)

    This is a good opportunity to point out that literal ( and ) used in the Replace-with zone need escaping with the \ before them. [Escaping is also needed for them to appear literally in the Find-what zone, but that is more well-known!]



  • Thank you so much for the solution and explanation Scott, I really appreciate it.


Log in to reply