Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .