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
  • 837
  • 8
  • 28

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
  • 561,645
  • 34
  • 376
  • 476