title: How to check a string against a possible large collection of prefixes and suffixes in Lucene?
body: <p>I have to implement a function that trims prefixes from a given string. The list of prefixes could be very large so it will be costly to try regular Scala functions <a href="https://www.scala-lang.org/api/2.12.2/scala/collection/immutable/StringLike.html#stripPrefix(prefix:String):String" rel="nofollow noreferrer">stripPrefix</a> one after the other. So I've turned to Lucene in order to create a FSA that will be smaller and more efficient testing for prefixes.</p>
  <p>Following this <a href="https://stackoverflow.com/questions/42176474/automaton-for-prefix-matching">Stackoverflow question</a> I discovered that the automaton I was looking for is the <a href="https://lucene.apache.org/core/8_6_1/core/org/apache/lucene/util/automaton/DaciukMihovAutomatonBuilder.html" rel="nofollow noreferrer">DaciukMihov Automaton</a>. But then I don't know how to use the automaton for getting which was the prefix matched or not against the string. So I have 2 complementary questions:</p>
  <ol>
  <li>How do you use a generic <code>Automaton</code> in order to get the start and
  end characters of a match?</li>
  <li>How do you force the match to happen at
  the beginning of the string?</li>
  </ol>