How to separate two numbers from text?



  • How can i join two lines which both have numbers. Try to comprehend with the example given below.

    What I’m having:

    54550 4208447963
    61186 7209982947
    59758 1765530261
    61538 7471871654
    24183 1399048005
    19948 6120524833
    55827 7214076491
    30842 9488550056
    32526 4053135693
    34275 8992850129
    

    What I want:

    54550
    4208447963
    61186
    7209982947
    59758
    1765530261
    61538
    7471871654
    24183
    1399048005
    19948
    6120524833
    55827
    7214076491
    30842
    9488550056
    32526
    4053135693
    34275
    8992850129
    

    These are adjacent lines.
    Please note: 1st line’s number is a constant 5 digit numeric value on the other hand the 2nd line’s number may change its digits in between 8 to 14 digits



  • Hello, @faisal-alam and All,

    You said :

    How can i join two lines which both have numbers.

    These are adjacent lines.

    Please note: 1st line’s number is a constant 5 digit numeric value on the other hand the 2nd line’s number may change its digits in between 8 to 14 digits

    In that case, the following regex S/R should solve your problem, very closely :

    SEARCH (?<=^\d{5})\x20(?=\d{8,14}(\R))

    REPLACE \1

    Important : You must click on the Replace All button, exclusively ( do not use the Replace button )


    Notes :

    • It searches for a space character \x20 , ONLY IF

      • Preceded with five digits \d{5} , exactly, beginning a line ^

      • Followed with a number between eight and fourteen digits \d{8,14} , ending the line \R

    • The line break chars are stored as group 1 due to the (\R) syntax

    • In replacement, the space char is, then, changed into the usual like-break of your file \1 ( the group 1 )

    Regards,

    guy038



  • @Faisal-Alam

    one alternative way might be to use the BetterMultiSelection plugin.



  • Do we just keep answering this person’s trivial data manipulations forever? Or do we request that said person start learning so that we can pursue more interesting things on this forum?



  • I know it can be frustrating to give help in the hope that one will learn from it.
    On the other hand, it may be nice for those who answer to be able to do so. Helper syndrome.
    Honestly, I didn’t question whether the OP had already asked several of these questions,
    but just thought, hey, this can be done easily without regex.
    In the end, however, I am of the opinion that those who want to give answers should be allowed to do so.



  • @Ekopalypse said in How to separate two numbers from text?:

    but just thought, hey, this can be done easily without regex.

    Yes and you present a good technique, something interesting to the forum.

    those who want to give answers should be allowed to do so

    Surely, and I can’t stop them.
    Just my efforts to keep us on track, and not being a continual back-and-forth data translation service for those that don’t choose to go off and learn how to do their own, with the basics given here.


Log in to reply