Possessive Quantification Example 3

Possessive Quantification: A Wizardly Example

In this example, we will explore the mystifying realm of possessive quantification, where the quantification of possession is not just about counting things, but about conjuring them into existence!

Using the power of regex, we will demonstrate the art of turning "cat's eye" into "cat's eyes" and "cat's paws" into "cat's paws".

Join me on this magical journey as we delve into the heart of the Regex Wizard's lair, where the quantification is not just a number, but a reality!

Previous Example Next Example Back to Possessive Quantification
import re

# Regex pattern for possessive quantification
pattern = r'\b\w+\\'  # match any word followed by an apostrophe

# Test strings
test_str1 = "cat's eye"
test_str2 = "cat's paws"

# Apply possessive quantification
result1 = re.sub(pattern, lambda match: match.group(0).rstrip("'") + "'s", test_str1)
result2 = re.sub(pattern, lambda match: match.group(0).rstrip("'") + "'s", test_str2)

print(result1)  # Output: cat's eyes
print(result2)  # Output: cat's paws