Regular Expression - Abbreviation Matching

B

Ben McClaren

Hi,

I'm trying to write two regular expressions that will match a sequence
of characters to a string and a string to a sequence of characters,
i.e.

The first: cms will match to centimetres and centimeters

and

The second: centimetres will match to cms and cm

Is this possible and if so how do I go about doing so?

Thanks, in advance,

Ben McClaren
 
J

John Bokma

Ben said:
Hi,

I'm trying to write two regular expressions that will match a sequence
of characters to a string and a string to a sequence of characters,
i.e.

The first: cms will match to centimetres and centimeters

and

The second: centimetres will match to cms and cm

Is this possible and if so how do I go about doing so?

Create two look up tables using hashes. A key could be an array ref in
case there are more solutions to one look up.

my %expand = (

cms => [ qw(centimetres centimeters) ],
);

You can match the most general form of your keys, and check if there
exists a key for the thing you matched in your hash.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top