How to remove blank spaces after a particular phrase



  • Hi, I wanted to remove the blank spaces after a particular phrase, for ex:

    1_start_of_file
    truncate table dbo.table_name
    eee
    truncate table dbo.table_name2
    333_end_of_file

    so, in the above file, i want ro remove any blank spaces after the phrase ‘truncate table’. Above is just an example, actual file is big, thanks.



  • @Vf-Dvr ,

    What you asked to do could be done using:

    • FIND = truncate table\h+
    • REPLACE = truncate table
    • SEARCH MODE = regular expression

    However, my bet is that it won’t be what you really want, because that will end up converting

    1_start_of_file
    truncate table                          dbo.table_name
    eee
    truncate table                       dbo.table_name2
    333_end_of_file
    

    to

    1_start_of_file
    truncate tabledbo.table_name
    eee
    truncate tabledbo.table_name2
    333_end_of_file
    

    … with no spaces between truncate table and whatever comes after.

    I am going to guess what you really wanted is to leave just one blank space after the phrase, resulting in

    1_start_of_file
    truncate table dbo.table_name
    eee
    truncate table dbo.table_name2
    333_end_of_file
    

    This could be accomplished by changing the REPLACE expression to truncate table\x20 (where \x20 is a fancy regex way of saying “literal space character”, which has the side benefit that can be seen in the forum posts and easily copied from the forum to paste into your REPLACE field.

    Also, please read and understand the following. Please be warned that following this advice is expected of anyone who asks more than one or two search/replace questions (and preferred from everybody):
    ----

    Please note: This Community Forum is not a data transformation service; you should not expect to be able to always say “I have data like X and want it to look like Y” and have us do all the work for you. If you are new to the Forum, and new to regular expressions, we will often give help on the first one or two data-transformation questions, especially if they are well-asked and you show a willingness to learn; and we will point you to the documentation where you can learn how to do the data transformations for yourself in the future. But if you repeatedly ask us to do your work for you, you will find that the patience of usually-helpful Community members wears thin. The best way to learn regular expressions is by experimenting with them yourself, and getting a feel for how they work; having us spoon-feed you the answers without you putting in the effort doesn’t help you in the long term and is uninteresting and annoying for us.

    ----

    Do you want regex search/replace help? Then please be patient and polite, show some effort, and be willing to learn; answer questions and requests for clarification that are made of you. All example text should be marked as literal text using the </> toolbar button or manual Markdown syntax. To make regex in red (and so they keep their special characters like *), use backticks, like `^.*?blah.*?\z`. Screenshots can be pasted from the clipboard to your post using Ctrl+V to show graphical items, but any text should be included as literal text in your post so we can easily copy/paste your data. Show the data you have and the text you want to get from that data; include examples of things that should match and be transformed, and things that don’t match and should be left alone; show edge cases and make sure you examples are as varied as your real data. Show the regex you already tried, and why you thought it should work; tell us what’s wrong with what you do get. Read the official NPP Searching / Regex docs and the forum’s Regular Expression FAQ. If you follow these guidelines, you’re much more likely to get helpful replies that solve your problem in the shortest number of tries.



  • Great, thanks Peter.


Log in to reply