const regex = /^(?:#JSGF) (?<version>V1.0) (?<encoding>[A-Z-0-9]+) (?<locale>[a-z]{2}-[A-Z]{2});$/gm;
// Alternative syntax using RegExp constructor
// const regex = new RegExp('^(?:#JSGF) (?<version>V1.0) (?<encoding>[A-Z-0-9]+) (?<locale>[a-z]{2}-[A-Z]{2});$', 'gm')
const str = `#JSGF V1.0 UTF-8 hu-HU;
grammar planmaster.hu;
<command_change_odontogram> = ( <change_to> [ a ] <odontogram_mode> [ felvételére | felvételre ] ) | ( <odontogram_mode> felvétele ) ;
<change_to> = ( váltás | válts | menj | ugrás | ugorj ) ;
<odontogram_mode> = ( státuszra | státuszhoz | státusz ) {state} | ( kezelés | kezelésre | kezeléshez | lépésekre | lépésekhez ) {treatment} ;
<command_full_jaw> = <all> * ( alsó {lower} | felső {upper} ) [ fogsor | állkapocs | fogak | fog ] <all> * <status> ;
<all> = mind | összes | teljes ;
<status> = ( <status1> | <status2> | <status3> ) {status} ;
<status1> = ( ép | alaphelyzet | alaphelyzetbe ) {1} ;
<status2> = ( hiány | hiányzik ) {2} ;
<status3> = [ szekunder ] ( szuvas | szuvasodott | szuvasodás ) {3} ;
<tooth18> = ( 18as | 18-as | tizennyolcas | nyolcas | ( 18 as ) ) {18} ;
<tooth17> = ( 17es | 17-es | tizenhetes | hetes | ( 17 es ) ) {17} ;
<tooth16> = ( 16os | 16-os | tizenhatos | hatos ) {16} ;
<tooth_region> = ( bal {left} | jobb {right} ) ( felső {upper} | alsó {lower} ) ;
<tooth_number> = ( <tooth18> | <tooth17> | <tooth16> | és ) ;
<command_select> = ( ( <tooth_number> + ) | <tooth_region> <tooth_number> + ) [ fog | fogak ] ;
`;
// Reset `lastIndex` if this regex is defined globally
// regex.lastIndex = 0;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for JavaScript, please visit: https://developer.mozilla.org/en/docs/Web/JavaScript/Guide/Regular_Expressions