'Replace tablespoon/s and teaspoon/s
I'm using BBEdit or Visual Code and I'm not too experienced with regex but would like to do a simple find and replace to all instances of "teaspoon(s)" (as in teaspoon or teaspoons) and "tablespoon(s)" with "tsp" and "tbsp".
replace:
1 tablespoon sugar
2 teaspoons salt
2 tablespoons butter
3 teaspoons crystal meth
with:
1 tbsp sugar
2 tsp salt
2 tbsp butter
3 tsp crystal meth
The replace search term should encompass all four variants in one go. Any help would be much appreciated.
Solution 1:[1]
You can capture the "b" from "table" to do it in one replacement:
search: \bt(?:a(b)le|ea)spoons?\b
replace: t$1sp
$1 is a placeholder for the captured content (the b if any).
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Casimir et Hippolyte |
