0

let's say I have a string like Michael is studying at the Faculty of Economics at the University

and I need to check if a given string contains the following expression: Facul* of Econom*

where the star sign implies that the word can have many different endings

In general, my goal is to find similar expressions within tables from the clickhouse database. If you suggest other options for solving this problem, I will be grateful

Baurzhan
  • 207
  • 4
  • 13

2 Answers2

1

Use any number of "word" chars for word tails and "word boundary" at the front:

\bFacul\w* of Econom\w*

consider case insensitivity too:

(?i)\bfacul\w* of econom\w*
Bohemian
  • 412,405
  • 93
  • 575
  • 722
1

If you want to match any lowercase letters following your two words use this:

\bFacul[a-z]* of Econom[a-z]*\b

If you want to match any optional letters following your two words use this:

\bFacul[A-Za-z]* of Econom[A-Za-z]*\b

Explanation:

  • \b - word boundary
  • Facul - literal text
  • [A-Za-z]* - 0 to multiple alpha chars
  • of - literal text
  • Econom - literal text
  • [A-Za-z]* - 0 to multiple alpha chars
  • \b - word boundary

If you want to be be more forgiving with upper/lowercase and spaces use this:

\b[Ff]acul[A-Za-z]* +of +[Ee]conom[A-Za-z]*\b
Peter Thoeny
  • 7,379
  • 1
  • 10
  • 20