vi3k6i5 / flashtext

Extract Keywords from sentence or Replace keywords in sentences.
MIT License
5.6k stars 600 forks source link

How to use Regular Expression with FlashText #118

Open BluePanda-io opened 4 years ago

BluePanda-io commented 4 years ago

This is probably an easy question that is already been answered but unfortunately, I can't figure this out or find someone that did already.

How can I use FlashText for Regex patterns?

Something that comes to mind a possible ways but doesn't work is:

from flashtext import KeywordProcessor
keyword_processor = KeywordProcessor()
keyword_processor.add_keyword('Big')
keyword_processor.add_keyword(r'\d{5}')
keywords_found = keyword_processor.extract_keywords('I love big Appsle 23234 ands Bay Area. 12345', span_info=True)
print(keywords_found)

As a result, we will have "big" and the corresponding position and "23234, 12345" and the corresponding position

Thank you for taking the time to answer me and excited to use your great library

thakur-nandan commented 4 years ago

Hi @milts10 ,

Unfortunately flashtext cannot handle regex patterns. You should use the regex module instead.

Kind regards, Nandan Thakur

BluePanda-io commented 4 years ago

Thank you so much for answering,

I am sorry for being such a newbie but what is the regex module and can I find the position of the regex using this module?

Basically, the only thing that I need is to input 2 different regexes for example and get back the position of this regex in the input text

Thank you for your time!!!!!

JJwangbilin commented 3 years ago

Thank you so much for answering,

I am sorry for being such a newbie but what is the regex module and can I find the position of the regex using this module?

Basically, the only thing that I need is to input 2 different regexes for example and get back the position of this regex in the input text

Thank you for your time!!!!!

@milts10 hello,I have the same question,How did you solve it?

Littlecowherd commented 3 years ago

@JJwangbilin Are you looking for this?