In Application Discovery, using search in file function, how can I use regular expressions to perform ANDing and ORing? Suppose I want to search for all IF statements that set variable A or set variable B in the THEN clause. Can this be constructed?
so I want a reg exp that would traps these two statements
ie. IF X=1 THEN A=2 IF Y=2 THEN B=3
but not
IF X=3 THEN C=1
thank you
Answer by JigaranuEduard (16) | Aug 04, 2017 at 04:54 AM
Hello @DANL_M.
I've done a more search and extended testing and I have found that:
checking the "Regular expression" in the "Search in files" Explorer option can help you ONLY if you are searching for a regular expression or syntax keyword that has been indexed already (so the search is done ONLY in the index containing the key words treated as regular expression; eg: from a code file the index will extract only keywords such if, then, else, do, when, dcl, return, etc and the search will match only the terms existing in this index)
as soon as you are entering some text like "A=" or anything else, the regular expression is of no use as it is not a keyword; I would strongly suggest to use simple search without resorting to the "regular expression" as it will search in all the file
also, please bear in mind that if the searched terms are in different lines, the result will contain the first term and the line where is present - eg: you search for "then m_txt !!= '11'x" in the code like if(length(trim(var_a.txt)) > 0) then m_txt !!= '11'x !! 'FN ' !! trim(var_a.txt); aktLL = length(m_txt); if(^writeLine()) then return(false); you will be shown only the line containing the first term - then in our case see image sif-eg.png attached.
Answer by JigaranuEduard (16) | Aug 03, 2017 at 10:45 AM
The OR-ing can be done using either comma "," or space" ".
I am not aware of any AND. Below you can find a list of possibilities for the search in files option in the Analyze Client:
For searching you can use 'simple text' term or regular expressions. Note: When 'regular expressions' option is checked regular expression matching is also done for file name.
For 'simple text' the following functionalities are implemented: ',' (comma) means OR: searching for 'termA,termB' will show occurrences (and files) that match any of the terms; ' ' (space) means consecutive terms: searching for 'termA termB' will show only occurrences that match both terms in this exact order. Space(s) right after comma is(are) ignored and multiple spaces are trimmed - considered as one; '?' means any one character: searching for 'abc?' will show occurrences of all 4 characters terms where the first three are 'abc'; '' means any term or any number of characters part of a term - this is so because searching/matching is done on indexed terms and not full text and a term is any sequence of valid characters delimited by separators. To see what characters are considered as a valid part of a term (and not a separator - ignored) see isJavaIdentifierPart(char ch) - to that the following characters are added: @,-,#. This means that characters like '', '(', ')', ','(comma), ':', '=' etc. are ignored(considered separators);
These can be mixeed.
For regular expressions: ',' (comma) means the same thing as above: 'regEx1,regEx2' is equivalent to 'regEx1|regex2'; ' ' (space) means the same thing as above; Note: the search term (both simple text and regular expression) has to fully match and indexed term to obtain a result. This actually means something in regular expression context where if you use something like an online regex validator/tester for the regex 'term' you will match 'term' plus any word containing 'term' (terms, terminates) for Search in files using regular expressions this is not the case - searching for 'term' will only show occurrences of 'term'. To obtain the same behavior you would have to use a regular expression like 'term\w*'.
HTH