Skip navigation
Currently Being Moderated

How to capture a located word in a line?

Feb 1, 2013 12:03 PM

It is possible to tag the last word (Corinne) in a line before a tab?


Larrue Corinne (\t)              3: 6-38

     Luusa Mer Klaus (\t)      4: 9-18


in order to insert a period:


     Larrue, Corinne (\t)      3: 6-38

     Luusa Mer, Klaus (\t)      4: 9-18

  • Currently Being Moderated
    Feb 1, 2013 12:15 PM   in reply to camilo umaña

    GREP find and replace




    replace with



    Mark as:
  • Currently Being Moderated
    Feb 1, 2013 12:14 PM   in reply to camilo umaña

    Sure. Using GREP, search for




    and replace with a period plus a space (or, based on your image, a *comma* and a space). (Note that instead of "\x{20}" you also can insert a single space, but that would disappear in the post! It works the same, though.)


    The expression "(?=[[:alpha:]]+\t)" is a *lookahead*, and matches 'any alphabetic character', at least one, as much as can be found, and followed by a single tab. Since it's a lookahead, it will be matched but not take part in the actual Replace operation; only the single space will, and it'll be replaced with the space+comma (or period).

    Mark as:
  • Currently Being Moderated
    Feb 1, 2013 12:24 PM   in reply to SRiegel

    Your query didn't format well on the web page (and I think it has an error)....


    I think I'd search for \s\<\w+\>\s?(?=\t) so that you include the leading whitepace before the second name and put the , in front of it. I also don't see the necessity for a shortest match limiter inside the word delimiters, but I added an optiona whitespace before the tab because I wasn't sure if there was one from the example. The error I spotted was /t instead of \t in your lookahead.

    Mark as:
  • Currently Being Moderated
    Feb 1, 2013 12:51 PM   in reply to Peter Spier

    Thanks, Peter.


    My grep as written worked on my small sample, but I had trouble pasting it into the fourm, and I made some errors in reentering it. (like the tab character being wrong, and the initial space being left off).

    I use these grep questions to help myself learn to use grep better, and I appreciate any critiques, or suggestions as to how to write it better.

    Mark as:
  • Currently Being Moderated
    Feb 1, 2013 1:25 PM   in reply to SRiegel



    The typo disappeared and the formatting is better now. Did you find a way to edit it? I didn't think you could once I responded to you.


    I do the same thing with the GREP questions, try to figure out what will work, then I wait for Jongware to post the elegant answer and try to remember what he does for next time.

    Mark as:
  • Currently Being Moderated
    Feb 1, 2013 1:33 PM   in reply to Peter Spier

    I was actually working on fixing it while you were posting. I had noticed some of the problems as soon as I posted. I still left the initial space off, thought. And I'm studing Jongware's response now, in hopes of understanding it well enough to use the concept in the future.

    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points