RegEx - how to select the second comma and everything after it

I am using UltraEdit. I have a text file containing lines like

Workspace\\Trays\\Dialogs\\Components, Expand, kThisComputerOnly, P_BOOLEAN },
WebCommonDialog Sign_Out, Left, kThisComputerOnly, P_INTEGER_RANGE(0, 4096) },
ThreeDTextDlg, x, kThisComputerOnly, P_INTEGER_RANGE(0, 4096) },
Preferences\\Graphics, CtxDbgMaxGLVersionMajor, kThisComputerOnly, P_INTEGER },

      

UltraEdit allows you to create PREL, UNIX and UltraEdit RegEx style. I need to select the second comma and everything to the end of the line and remove it.

Using regexpal.com I've tried several different approaches but can't figure it out.

/,\s.+/ selects the first comma
/[,]\s.+/ same as above

      

I cannot figure out how to choose the second command and further.

I also searched StackOverflow and found some examples but couldn't change them to work for me.

Thank.

+3


source to share


1 answer


You can use Perl's regex option with the following pattern:

^([^,]*,[^,]*),.*

      

and replace with \1

.



See regex demo .

More details

  • ^

    - beginning of line
  • ([^,]*,[^,]*)

    - Group 1 (later referred to with a \1

    backlink from the replacement pattern):
    • [^,]*

      - any 0+ characters other than comma (to prevent line overflows, add \n\r

      negative characters to the class - [^,\n\r]*

      )
    • ,

      - comma
    • [^,]*

      - any 0+ characters except comma
  • ,

    - comma
  • .*

    - any 0+ characters other than line break characters
+3


source







All Articles