string search from list of keywords
anyone know of a simple way to search a blob of text from a list of keywords in one fell swoop, without having to iterate through each keyword and perform an individual search? Ex.
s keywords="This,blob,text"
s text = "This is a sample blob of text"
i text[keywords w "hit"
Comments
See %Regex.Matcher
Example:
<FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">text </FONT><FONT COLOR="#000000">= </FONT><FONT COLOR="#008000">"This is a sample blob of text"</FONT><FONT COLOR="#000000">, </FONT><FONT COLOR="#800000">keywords</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#008000">"This,blob,text"</FONT><FONT COLOR="#0000ff">s </FONT><FONT COLOR="#800000">matcher</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#000080">##class</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#008080">%Regex.Matcher</FONT><FONT COLOR="#000000">).</FONT><FONT COLOR="#0000ff">%New</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#0000ff">$tr</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">keywords</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"|"</FONT><FONT COLOR="#000000">)), </FONT><FONT COLOR="#800000">matcher</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Text</FONT><FONT COLOR="#000000">=</FONT><FONT COLOR="#800000">text </FONT><FONT COLOR="#0000ff">w</FONT><FONT COLOR="#000000">:</FONT><FONT COLOR="#800000">matcher</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Locate</FONT><FONT COLOR="#000000">() </FONT><FONT COLOR="#008000">"hit"</FONT><FONT COLOR="#000000">,!
</FONT><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#800000">matcher</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">ResetPosition</FONT><FONT COLOR="#000000">()
</FONT><FONT COLOR="#0000ff">while </FONT><FONT COLOR="#800000">matcher</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Locate</FONT><FONT COLOR="#000000">() </FONT><FONT COLOR="#800080">{</FONT><FONT COLOR="#0000ff">write </FONT><FONT COLOR="#008000">"Found "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">matcher</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Group</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">" at position "</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">matcher</FONT><FONT COLOR="#000000">.</FONT><FONT COLOR="#0000ff">Start</FONT><FONT COLOR="#000000">,!</FONT><FONT COLOR="#800080">}</FONT>
USER><FONT COLOR="#0000ff">d </FONT><FONT COLOR="#000000">^test</FONT> hit Found This at position 1 Found blob at position 18 Found text at position 26
Or see $locate: Using Regular Expressions in Caché
Example:
USER><FONT COLOR="#0000ff">w $locate</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">text</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#0000ff">$tr</FONT><FONT COLOR="#000000">(</FONT><FONT COLOR="#800000">keywords</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">","</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#008000">"|"</FONT><FONT COLOR="#000000">),1,</FONT><FONT COLOR="#800000">e</FONT><FONT COLOR="#000000">,</FONT><FONT COLOR="#800000">x</FONT><FONT COLOR="#000000">)</FONT> 1
This is perfect, thanks!