Question

I have semantic library containing database fields with possible/matching matching synonyms in previous column i.e. goods id | products_id - items id | products_id - things id | products_id.

I am required to match above fields in result of user entered utterance and have the system to select the relevant database field ( in above case "products_id").

The problem is that user might mention above synonym to their choice and matching function can fail if the word order is removed i.e.:

User: Show me the id of goods.

User: I want to see items and their id.

User: can you display things with id numbers.

Could you advise on what accurate regular expression syntax/combination should be used in this case as its quite laborious and I am trying different ways to make it work. So far I have tried positive lookahead but not sure.

^(?=.*goods)(?=.*id).*$
Was it helpful?

Solution

Try with this regex:

^(?=.*\b(?:goods?|things?|items?)\b)(?=.*\bid\b).*$
                                ^---place here if you want to add more

Place your words inside the (...) separated with a pipe(|). Notice, I have used s? which means s can exists or not. For example goods? with support both good and goods

Try this Online Demo

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top