1

I have the following adverbs:

fastly onffly fly incomprehensibly totaly happily 

lily sly more happily 

most seriously

I would like to match only normal form of adverb ending with ly, not comparative and superlative that end with ly.

The above example, I dont want to match a word ending with ly if the previous word is more or most.

I tried to do this:

(?:^[more|most])\s?\w*ly

But I am not getting any match. Any idea? demo that I tried to rework.

tavalendo
  • 857
  • 2
  • 11
  • 30
  • I am not sure that regular expressions is what you are after here.... you might need a Natural Language Processing (NLP) library. – npinti Dec 04 '18 at 14:14
  • 1
    Try `(?<!more |most )\b\w*ly`, see [this demo](https://regex101.com/r/ypx16D/1). Or even `(?<!\bmore |\bmost )\b\w*ly` – Wiktor Stribiżew Dec 04 '18 at 14:15
  • I am trying without libraries. Want to learn regex to the core. – tavalendo Dec 04 '18 at 14:15
  • If you are using regex there is some regex library behind the scenes. There is no "universal regex". [This one](https://regex101.com/r/gG50rK/1) - `\b(?:more|most)\s+\w*ly(*SKIP)(*F)|\w*ly` - will only work with PCRE library, e.g. – Wiktor Stribiżew Dec 04 '18 at 14:15
  • very interesting @WiktorStribiżew. Lots of learning here! – tavalendo Dec 04 '18 at 14:22

1 Answers1

1

There is no "universal regex" and if you are using regex there is some regex library behind the scenes. In your case, you experimented with PCRE regex library, so you may consider either

\b(?<!\bmore |\bmost )\w*ly\b

See demo. Or, a SKIP-FAIL regex:

\b(?:more|most)\s+\w*ly(*SKIP)(*F)|\w*ly\b

See another regex demo.

Details

  • \b - word boundary
  • (?<!\bmore |\bmost ) - there should be no whole word more or most followed with 1 space immediately before the current location
  • \w* - 0+ word chars
  • ly\b - ly word ending (ly followed with a word boundary).

In the SKIP-FAIL regex, \b(?:more|most)\s+\w*ly matches all more and most ~ly word combindations, discards them and matches words with ly suffix in other locations.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563