Regular expression for matching mapcodes
npm install mapcode-regex
import mapcodeRegex from 'mapcode-regex';
mapcodeRegex().test('4J.Q2');
//=> true
mapcodeRegex().test('Hawaii ZSR.3J');
//=> true
mapcodeRegex().exec('This is a mapcode FRA 4J.Q2')[0];
//=> 'FRA 4J.Q2'
'Multiple FRA 4J.Q2 Hawaii ZSR.3J mapcodes'.match(mapcodeRegex());
//=> ['FRA 4J.Q2', 'Hawaii ZSR.3J']
If you run the regex against untrusted user input in a server context, you should give it a timeout.
I do not consider ReDoS a valid vulnerability for this package.
You can use clone-regexp to change the flags. In this case, maybe remove the global flag.
- mapcode - Find mapcodes in a string