Menu

RegEx: Find comma not followed by space

Maleko
2009-02-24
2012-11-13
  • Maleko

    Maleko - 2009-02-24

    Hi folks. I am not sure if i need to use regex to do this. I am looking for a way to find for a comma sign which is not followed by space(s)

    eg;

    "menu_addblank(g_MainMenuID, 0,szMenuName,20)"

    In this string, the first comma has space after it. So only the last 2 comma's will match

    Please reply if you have any idea

    Thanks

     
    • Maleko

      Maleko - 2009-02-27

      Thanks all!

       
    • Greg

      Greg - 2009-02-24

      I would use RegEx myself. I would use the find string:

        \,[^ ]

      comma followed by any character except a space.

      Make sure the Regular Expression mode is selected otherwise it won't work.

       
    • Maleko

      Maleko - 2009-02-24

      Hey thanks that works! What about replacing those comma's with comma that has space?

      "menu_addblank(g_MainMenuID, 0,szMenuName,20)"

      to

      "menu_addblank(g_MainMenuID, 0, szMenuName, 20)"

      Find what: \,[^ ]
      Replace with: ?

       
      • Greg

        Greg - 2009-02-24

        If you want to replace those commas WITHOUT a space with say an asterisk (*) then

          Find: \,[^ ]
        Replace With: *_   (where underscore represents a space)

        If you want to delete the comma then

          Find: \,[^ ]
        Replace With: _    (where underscore represents a space)

        This replaces the comma space with just a space.

         
      • Fool4UAnyway

        Fool4UAnyway - 2009-02-24

        If you want to make sure there's (only) one space character after _each_ comma, use this:

        Find field:
        ,[ \t]*

        There is no need to precede the comma by \.

        Replace field:
        , _ (without the underscore)

        This, in effect, will add a space character after each comma, while not (re-)placing any other white space, be it (a) space character(s) that were already there or even tab characters.

         
    • Greg

      Greg - 2009-02-24

      Oops, I only saw half the question.

      The answer is:

      Find: \,([^ ])
      Replace with: , \1     (comma, space, backslash one)

      We'll have a description of regular expression operators in the Wiki shortly.

       
MongoDB Logo MongoDB