Skip to main content
dublove
Legend
May 25, 2025
해결됨

Still a little confused about \K. How do you leave just Jane and Purus?

  • May 25, 2025
  • 1 답변
  • 340 조회
Sample:
Lin YiJuan Jane
Pu LuShi Purus

Regular expression:
(.+? +\w+){1}\K.*

 

I saw a tutorial where he did it in excel.
He intercepted the last name.

 

Can it be implemented in ID?


Result:

Jane

Purus

 

최고의 답변: m1b

If you want to target just the one word (after the first two), you could use this:

^(?:[^\h\r]+\h){2}\K([^\h\r]+)

But you mean you want to find/change Lin YiJuan Jane to just leave only Jane behind—then try this grep:

^(?:[^\h\r]+\h){2}([^\h\r]+)

and replace with

$1

 Notice that the first group is a non-capturing group, so $1 points to the 2nd one.

Also notice that there is no \K — we don't want it here, because we *want* to match the first words so we can change them.

1 답변

m1b
Community Expert
Community Expert
May 25, 2025

Yes \K works well in Indesign. It means "match reset". It just discards any matched characters made up until that point, so the pattern will start matching again.

 

This is how I would do the pattern:

^([^\h\r]+\h){2}\K.*

 It seems more logical to me: from the start of the line, you match characters which are not a horizontal space (\h) or a carriage return (\r) and then a horizontal space (eg. a space character, you could also just put a literal space " " ) and it is saying match 2 of those, ie 2 words with a space after them. Then discard it all (\K) and start matching anything after that.

- Mark

dublove
dublove작성자
Legend
May 25, 2025

Yes, you are much clearer in this thought.
So how do I use him, I just want to stay:
Jane.
Purus.

 

m1b
Community Expert
m1bCommunity Expert답변
Community Expert
May 25, 2025

If you want to target just the one word (after the first two), you could use this:

^(?:[^\h\r]+\h){2}\K([^\h\r]+)

But you mean you want to find/change Lin YiJuan Jane to just leave only Jane behind—then try this grep:

^(?:[^\h\r]+\h){2}([^\h\r]+)

and replace with

$1

 Notice that the first group is a non-capturing group, so $1 points to the 2nd one.

Also notice that there is no \K — we don't want it here, because we *want* to match the first words so we can change them.