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"
Discussion (2)0
Comments
See %Regex.Matcher
Example:
s text = "This is a sample blob of text",
keywords="This,blob,text"
s matcher=##class(%Regex.Matcher).%New($tr(keywords,",","|")),
matcher.Text=text
w:matcher.Locate() "hit",!
d matcher.ResetPosition()
while matcher.Locate() {write "Found ",matcher.Group," at position ",matcher.Start,!}
USER>d ^test
hit
Found This at position 1
Found blob at position 18
Found text at position 26Or see $locate: Using Regular Expressions in Caché
Example:
USER>w $locate(text,$tr(keywords,",","|"),1,e,x) 1
This is perfect, thanks!