Suppose I wish to match the following with a regular expression:
Convert 2g of NaOH into moles.
Convert 3.2 grams of Chlorine into mol.
How many moles are in 67 g of Sodium Chloride?
434 mol of Sodium to Grams.
The requirements are:
- Both the terms
g
/grams
andmol
/moles
need to appear in the string - These terms must be on their own, i.e. not as parts of longer words like
molecules
.
How could I use a single regex to match all 4 cases?
So far I have tried this:
~'mol|g|Grams/g
but it also matches terms such as:
32 mol
gravity of molecule