Re: How do I find possible matches using regular expression?




Andy wrote:
Hi there,

I'm trying to do some predicting work over user input, here's my
question:

for pattern r'match me', the string 'no' will definitely fail to match,
but 'ma' still has a chance if user keep on inputting characters after
'ma', so how do I mark 'ma' as a possible match string?


The answer is: Using regular expressions doesn't seem like a good idea.
If you want to match against only one target, then
target.startswith(user_input) is, as already mentioned, just fine.
However if you have multiple targets, like a list of computer-language
keywords, or the similar problem of an IME for a language like Chinese,
then you can set up a prefix-tree dictionary so that you can search the
multiple target keywords in parallel. All you need to do is keep a
"finger" pointed at the node you have reached along the path; after
each input character, either the finger gets pointed at the next
relevant node (if the input character is valid) or you return/raise a
failure indication.

HTH,
John

.



Relevant Pages

  • Re: User Input issue
    ... I have an issue with user input that I have been trying to figure out ... Unless you terminate the string with a newline the output might not appear ... An int has to be at least of 16 ... covered strings yet (I'm a college freshman in a Programming I/Novice ...
    (comp.lang.c)
  • Copy an excel file to new created folder
    ... You can assemble the string on the ... fly by concatenating the user input onto the rest of your ... >For each file folder batch created, ... include an excel ...
    (microsoft.public.excel.programming)
  • Re: writing user specified files
    ... What datatype does dlmread take? ... What datatype does your user input ... If it's a literal string, ... How do think you would call dlmread with your user input? ...
    (comp.soft-sys.matlab)
  • Re: converting int values to other formats
    ... struct char_map {int in, int out}; ... Then when you receive an input character, you search the first member ... You can search the input string for the input character with strchr, ...
    (comp.lang.c)
  • Help w/ current Find macro so it will recognize possible trailing letters
    ... The code below performs a search of PO# based on user input. ... Public FindPOVal As String ... 'This is for the PO/PL search via UserForm12. ... Dim PO_Column As Range ...
    (microsoft.public.word.vba.general)