regex - Regular Expression for irregularly occurring repeating string -
i searched have not found answer question - maybe obvious no 1 else had ask...
i using ultraedit 16.00
run regular expressions in perl mode
...
situation:
i have delimited string can contain variable number of repeating segments must adhere specific format. these segments occur randomly throughout delimited string.
example:
clp*data*data*data~ref*data*data~n1*data*data*data~**cas*oa*29*99.99**~amt*i*99.99~svc*data*data*data*data~**cas*pr*99.99**~**cas*co**99.99**~dtm*150*date~amt*b6*99.99~svc*data*data*data*data~cas*pr*n16*99.99~**cas*co* *99.99**...line continues here.
correct format - cas*oa*29*99.99~
incorrect format 1 - cas*oa* *99.99~
incorrect format 2 - cas*oa**99.99~
goal:
identify strings of cas segments adhere format.
things i've tried:
(btw: know regular expressions not optimized, please give me break)
cas segment missing value or containing 1 or more spaces
cas\*(oa|pr|cr|co)\*\*[-]?[\d]+\.?[\d]{0,2}
~ matches first instance if finds
cas\*(oa|pr|cr|co)\*[\s]+?\*[-]?[\d]+\.?[\d]{0,2}
~ matches first instance if finds
cas segment not missing value or containing space(s)
cas\*(oa|pr|cr|co)\*[^0-9a-z]+?\*[-]?[\d]+\.?[\d]{0,2}~
again, matches first instance
negative lookahead using combinations of above (i new trying approach)
^(?:(?!ab).)+$
- ab
=> one of above regular expressions
- never got work
question:
how write regular expression enforce/validate format of every cas instance no matter how occurs (there potential 0 instances)?
to every cas instance in string valid there not exist @ least 1 invalid cas sequence. approach getting @ negative lookahead simplest way represent - here's example:
/^(?!.*cas(?!<whatever matches valid cas instance>))/
basically: "make sure there not exist in string instance of cas not followed whatever matches valid cas instance". replace contents of second negative lookahead, , include whatever before 'cas' indicates start of cas instance.
as can see, don't need match string start finish want.
Comments
Post a Comment