Sample Header Ad - 728x90

How to use regex negative lookahead?

3 votes
2 answers
4555 views
I'm trying to use iTerm2 profile triggers on my mac to change the prompt if I leave my home directory. This rule should only apply when the node I'm on has a hostname of headnode. The prompt will also include the machine's location in parenthesis after the hostname. I'm trying to build a regex that will match any directory unless it includes ~. So it should match: [jbutryn@headnode (us-west-a) /]$ but not: [jbutryn@headnode (us-west-a) ~]$ or [jbutryn@headnode (us-west-a) ~/tmp]$ etc. Currently I'm building my regex like this: \[.*\@headnode.*(?!\~).*]. But that matches all examples above. Does anyone know what I'm doing wrong? Thanks!
Asked by jesse_b (41447 rep)
Aug 9, 2017, 03:48 PM
Last activity: Jan 19, 2022, 05:48 PM