4

I'm using UltraEdit. I have a text file that contains strings like this

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 PERL, UNIX and UltraEdit style RegEx. I need to select the second comma and everything to the end of the line and delete 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 can't figure out how to select the second command and beyond.

I have also search StackOverflow and found several examples but couldn't change them to work for me.

Thanks.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
Brad Askins
  • 53
  • 1
  • 1
  • 6
  • 2
    Try `^([^,]*,[^,]*),.*` and replace with `\1` with a *Unix* regex option. – Wiktor Stribiżew May 23 '17 at 15:57
  • 1
    @BenShelton why bother with a non-capturing group when you don't apply any quantifier to the grouped tokens? Isn't `,.*,` semantically identic? Also I don't think that's what OP wants to delete – Aaron May 23 '17 at 16:00
  • in Regexpal.com, `^([^,]*,[^,]*),.*` selected the whole line and UltraEdit didn't find a match. – Brad Askins May 23 '17 at 16:01
  • @BradAskins: It does select the whole line, but if you replace with `\1`, the start of the line up to the second `,` should remain. See https://regex101.com/r/1mGaCM/1 – Wiktor Stribiżew May 23 '17 at 16:02
  • @BradAskins it is supposed to select the whole line, but then you use capturing groups to replace the whole line by the part you want to keep. For the UltraEdit part, do you happen to know what is their regex implementation? – Aaron May 23 '17 at 16:02
  • in regexpal.com `(?:,.*,)` selected the first comma to the end of the line – Brad Askins May 23 '17 at 16:02
  • Ah got it! `^([^,]*,[^,]*),.* ` using PERL RegEx in UltraEdit did the trick! Thank you. – Brad Askins May 23 '17 at 16:06

1 Answers1

7

You may use a Perl regex option with the following pattern:

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

and replace with \1.

See the regex demo.

Details:

  • ^ - start of string
  • ([^,]*,[^,]*) - Group 1 (later referred to with \1 backreference from the replacement pattern):
    • [^,]* - any 0+ chars other than a comma (to prevent overflowing across lines, add \n\r into the negated character class - [^,\n\r]*)
    • , - a comma
    • [^,]* - any 0+ chars other than a comma
  • , - a comma
  • .* - any 0+ chars other than line break chars as many as possible
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563