All,
Trying to explore Regular Expressions a little better . I can achieve what I want with a simple Contains() - but trying to see what the equivalent would be using Regular Expressions.
The regex I have doesn't work the way I expect it to , can somebody point me to the equivalent regex and explain what I have gotten wrong ?
Clear Log(); Clear Globals();
dt = Open( "$SAMPLE_DATA/Cities.jmp" );
dt:city[2] = "aLBUQUERQUE";
CityList = dt:City << Get Values;
Des = list();
for(i = 1 , i <= N Items(CityList),i++,
If(!IsMissing(Regex(Char(CityList[i]),"^a|A[LB]*")),
Insert Into(Des,CityList[i]);
);
);
/*for(i = 1 , i <= N Items(CityList) , i++,
If(Contains(CityList[i],"aLB")|Contains(CityList[i],"ALB"),
Insert Into(Des,CityList[i]);
);
);*/
Show(Des);
//Close All(Data Tables,"No Save");
Right now you are matching either an 'a' at the beginning of the string ('^a') or an 'A' followed by zero or more letters 'L' or 'B' ('A[LB]*'). Some notes:
You probably want this: "^(a|A)LB.*$", or this: "^[aA]LB.*$"
Des = {"ALBANY", "aLBUQUERQUE"};
Check out regexr.com, it not only helps check your code but has good 'reference' and 'cheatsheet' sections on the left. I almost always turn multiline on (flags in the upper right).
Edited to clarify that match can be anywhere inside the string.
Right now you are matching either an 'a' at the beginning of the string ('^a') or an 'A' followed by zero or more letters 'L' or 'B' ('A[LB]*'). Some notes:
You probably want this: "^(a|A)LB.*$", or this: "^[aA]LB.*$"
Des = {"ALBANY", "aLBUQUERQUE"};
Check out regexr.com, it not only helps check your code but has good 'reference' and 'cheatsheet' sections on the left. I almost always turn multiline on (flags in the upper right).
Edited to clarify that match can be anywhere inside the string.