Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Using the Perl regex engine, I can't figure out how to extract the last item in a line where items are split using the TAB character.

Here's an example from the Process Explorer log file:

^advapi32.dll\tAdvanced Windows 32 Base API\tMicrosoft Corporation\t5.1.2600.5755\tC:\WINDOWS\system32\advapi32.dll$

I tried the following, to no avail:

  • \t\w$: "Search string '\t\w$' not found!". Makes sense, as "\" isn't taken into account
  • \t[^\t].+?$: Starts from the second column
  • [^\t].+?$: Whole line

Any idea?

Thank you.

share|improve this question

2 Answers 2

up vote 1 down vote accepted

Use greediness of the wildcards: they will eat up as much as the can. For example if you want to match a whole line, use: ^.*\t([^\t]+)$. The ^.*\t matches everything that precedes a tab (including it) and the ([^t]+)$ group matches what you are looking for (and you can reference it with $1 in this case).

share|improve this answer
    
Thanks for the info. Problem solved. –  OverTheRainbow Nov 19 '12 at 13:59

You were not far : very simply \t[^\t]+$ (or \t([^\t]+)$ if you can capture group from the result (the group you're looking for is inside the parenthesis)

share|improve this answer
    
Thanks but I tried "\t([^\t]+)$" and it simply removes the last\t before the last item –  OverTheRainbow Nov 19 '12 at 13:59
    
Can you explain further what you're doing with these regexp, exactly ? Because I can assure you that this one matches what you need. –  Orabîg Nov 19 '12 at 14:42
    
Ok, forget it. I just saw you gave credit to another one... –  Orabîg Nov 19 '12 at 14:43

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.