nurulc / incr-regex-package

A node package for incremental regular expression parsing in JavaScript; useful for input validation
ISC License
13 stars 1 forks source link

function to skip the node #3

Closed ajopjo closed 4 years ago

ajopjo commented 4 years ago

Hi:

I'm looking at the package to do a reg ex search for the validity of a string.

I have a requirement in which a user enter a "" to skip some of the nodes in the search. As an example if my regex is 536X[5|8][A-Z]+ a user enters 55A. So, is there any way I can search a character in the FSM node and if its not matching move to the next node and search. Help on this will be highly appreciated

nurulc commented 4 years ago

Hi, Thanks for your interest. If I understand your requirement to be effectively convert the regexp to the following:  You would like items that can be automatically filled in to be done and the user only need to input the values where there is a choice to make: The following code might help: var iRX = require('incr-regex-package');var { RXInputMask } = iRX; // little helper functionfunction ins(rxi, str) {    for(var i=0; i<str.length; i++) { rxi.input(str.charAt(i)); }     return rxi; } var im = new RXInputMask({pattern: "536X[5|8][A-Z]+"}); ins(im,"55A")assert(im.isDone() === 'OK')assert(im._getValue() === '536X5A')

Best Wishes Nurul

On Tuesday, May 26, 2020, 01:25:44 PM EDT, Ajo John <notifications@github.com> wrote:  

Hi:

I'm looking at the package to do a reg ex search for the validity of a string.

I have a requirement in which a user enter a "" to skip some of the nodes in the search. As an example if my regex is 536X[5|8][A-Z]+ a user enters 55A. So, is there any way I can search a character in the FSM node and if its not matching move to the next node and search. Help on this will be highly appreciated

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub, or unsubscribe.

nurulc commented 4 years ago

var iRX = require('incr-regex-package'); var { RXInputMask } = iRX; // little helper function function ins(rxi, str) { for(var i=0; i<str.length; i++) { rxi.input(str.charAt(i)); } return rxi; } var im = new RXInputMask({pattern: "536X[5|8][A-Z]+"}); ins(im,"55A"); assert(im.isDone() === 'OK'); assert(im._getValue() === '536X5A');

ajopjo commented 4 years ago

Thank you @nurulc . have you incorporated apis to generate valid values from a regular expression, i saw that comment as part of the road map. Thanks!!

nurulc commented 4 years ago

The capability is a part of the package