4
$\begingroup$

I have a large text file that I need to search for certain substrings and I would like to use the speed-up that TextSearch gives. Unfortunately, with TextSearch queries will only match entire words:

f = Export["~/test.txt", "1234 1234"];
TextSearch[CreateSearchIndex@f, SearchQueryString["*23*"]]

enter image description here

I'd prefer not to use StringCases as it is very slow on the large document. Is there some way around this?

$\endgroup$
  • $\begingroup$ Is it not Import? $\endgroup$ – David G. Stork May 3 '18 at 23:32
  • $\begingroup$ And then after import... $\endgroup$ – M.R. May 3 '18 at 23:32
  • $\begingroup$ Try maybe "23~" as the search string. ~ is supposed to indicate a close but non-exact match. It does work in your simple case, but I don't know how well it would perform on a real example. $\endgroup$ – MarcoB May 4 '18 at 3:15
5
$\begingroup$

You may use SearchQueryString in TextSearch.

f = Export["~/test.txt", "helloworld"];
TextSearch[CreateSearchIndex@f, SearchQueryString["hello*"]]

Mathematica graphics

Hope this helps.

$\endgroup$
  • $\begingroup$ Thanks @Edmund! See my update, we've almost got it I think $\endgroup$ – M.R. May 4 '18 at 1:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.