Perl regex matching: Match string with single word only, how to use negative lookbehind lookahead as well -


i'm genuinely exhausted in trying regex work. i'm using perl regex in sas. if me i'd appreciate it. have 3 questions, consider following lines of text (the line numbers there reference):

1 weight 2 weightchange 3 weight change 4 weight percentile 5 change weight 6 percentile weight 7 **** weight pre op 8 water weight 9 weight percentile 10 myocardial infarction 
  1. how use regex match 1 not 2-9? (is way match word @ beginning , end simultaneously?)

  2. how use regex , negative lookahead / lookbehind assertions match 1 , explicitly exclude 2-6?

  3. how modify regex suitable solve q2 exclude 7 , 8?

bonus question: how long did take good @ using regex?

thank you!

1) @barmar mentioned already: ^weight$ fine doing you're asking. sure that's want though, i.e. "weight" on line itself?

2) /(?<!percentile )(?<!change )weight(?! ?change| percentile)/. negative lookbehinds can't written (?<!change |percentile ) re engine not support variable width lookbehind matches zero-width can list them separately. looks awfully specific though. fail e.g. if text contained these words separated line break.

3) add negative lookbehind **** , water.

i'm not @ regex :) , never sat down , decided learn ins , outs, that's pretty useless if don't have use case; you'll forget in short while. i've been using regexen on 20 years i'm still learning new things, how match unicode properties few weeks ago.


Comments