0

I am looking for word matches from a lookup, to an excel sheet.

Say, for example, the word I am looking for is stackexchange.

I can have the following:

  • stackexchange
  • stackexchange is ok
  • \stackexchange\
  • my_stackexchange-is ok
  • my-stackexchange_is ok
  • my stackexchange.
  • my.stackexchange.is.ok
  • .stackexchange.

I cannot have

  • mystackexchange is ok my
  • stackexchangeis ok
  • mystackexchangeisok

I have managed all of them, apart from if the word group starts or ends with stackexchange e.g.

  • stackexchange is ok
  • my stackexchange

I can handle

  • .stackexchange.
  • \stackexchange\

Just not

  • stackexchange is
  • my stackexchange

If that makes sense (sorry if I am labouring a point).

The regex I have is

[-|_| ]?[^a-zA-Z\d]stackexchange[-|_| ]?[^a-zA-Z\d]

Any ideas people?

Hairy
  • 101
  • 7
  • 1
    `(?:^|[-_ ]?[^a-zA-Z\d])stackexchange(?:$|[-_ ]?[^a-zA-Z\d])` or `(?<=^|[-_ ]?[^a-zA-Z\d])stackexchange(?=$|[-_ ]?[^a-zA-Z\d])` – Wiktor Stribiżew Oct 16 '18 at 08:14
  • Thanks @WiktorStribiżew - Just what I needed, I thought it would be somethign fairly trivial, but not that great at REGEX yet. Thanks again. – Hairy Oct 16 '18 at 08:28
  • [Groups](https://www.regular-expressions.info/brackets.html) and [anchors](https://www.regular-expressions.info/anchors.html) are rather basic notions in regex, I suggest you devote a couple of minutes to read about them to avoid such issues in future. – Wiktor Stribiżew Oct 16 '18 at 08:31

0 Answers0