Match on word, unless this word precedes it

Can you have more than one “hear”? eg.
hear /issues close/ do nothing, return
hear /close/ do stuff

No, each hear gets the message independently and will run. So even though the first won’t respond, the second will still pick up /issues close/ (which is what is happening today).

I think I can fix this using additional logic, in fact, I just did.
https://github.com/cpradio/sp-team-jarvis/blob/552c2d58b5a206b2298fafebb533cc8b8a1f25a1/scripts/close.coffee#L16-L23

I was overcomplicating it before, oh well, at least I know the lack of Lookbehinds can be restrictive to RegEx in JavaScript. I can’t believe I forgot that I had the rawText available for more parsing. I should have known that.

1 Like

I know you say don’t want to use javascript to solve this problem, but in playing with it I came up with a method that does return the correct answer. You may be able to use aspects of this to solve your more restricted problem

<script type="text/javascript">
 var str="that was close, wasn't it! issues close #32. Keep your tissues close to your nose";
 var re=/close/gi;
 var result=1, build="",lftCon, subSearch, cnt;
 cnt=0;
 build='<p><b>Test</b>: \"'+str+'\"<\/p>\n';
 while(result)
  { result=re.exec(str); 
    lftCon=RegExp.leftContext.substr(-15,15);
    subSearch=lftCon.indexOf(" issues");    
    if(subSearch == -1)
       { if(result)             
          { cnt++;
            build+='<br><p>match '+cnt+' = >'+result+'\<<\/p>\n';
            build+='<p>left context= >'+lftCon+'\<<\/p>\n';
            build+='<p>chars: '+result.index+'-'+re.lastIndex+'<\/p>';
           } 
       } 
  }
  document.getElementById("wrap").innerHTML=build;
</script>

The RegExp exec() method allows you to capture a left context string next to the match. You can then search this for unacceptable words like “issues”. If it exists you move on to find the next match.

You will note that I added another phrase to the search string which contains the word “tissues”. If you run the script you will find that “issues close” is rejected, but “tissues close” is OK.

It’s not a “don’t want to” - it’s a “cannot use JavaScriot”. :frowning:

@cpradio

I’m watching, with bated breath… but have nothing useful to contribute :frowning: I will think more on it.

No worries, I’m fairly certain it can’t be done in a single RegEx, so the two RegEx approach I used in post #23 is more than sufficient for now.

1 Like

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.