java - Regular expressions on Scala - Searching from the beginning of String -


currently, when search "th" matches "the" "these" , "other"...i don't want "other" because not @ beginning of word.

i'm trying use regular expressions on scala , running problems. having trouble implementing "\a" matches @ beginning of string.

i'm working on autocomplete tool code seen below , i'm using contains...however matches on part of word. what's best way match start of word using \a?

val newlist = arraybuffer[string]() val pattern = new regex (\\a searchtext)  def searchlist (searchtext:string):unit = {     println("search has been called")     println(searchtext)     for(s <- words){         println("for test")         if(s contains(searchtext)){             println("if test")             newlist += s              println(newlist.mkstring("\n"))         }     } } 

use startswith instead of contains, search beginning of string.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -