searching files for regular expressions

General APL language issues

searching files for regular expressions

Postby DanB|Dyalog on Thu Apr 21, 2016 10:26 pm

Sometimes you want to look for APL code in text files.
The user command ]find can be used to do that.

If you give it a simple string to search it will, by default, look for that string in all the .dyalog files in your current SALT workdir, that is the first folder listed when you do
Code: Select all
    ]settings workdir

If you wish to look into a different folder you can use the -folder= modifier to specify it.
If you wish to use different file extensions you can use -types=abc,def,etc to specify them.
For example, to find ABC in text (.txt) files in folder \temp:
Code: Select all
    ]Find ABC -folder=\temp    -types=txt                                             

]FIND can also search using regular expressions. To do so you use the switch -regex.
For example to look for code where a name starting with 'GUI' is assigned you could use
Code: Select all
]find GUI.*?←  -regex

Sometimes you may find hits in text and comments. If this is a problem you can use ]FIND with the following expression - here I want to find ABC not in comments and not within text:
Code: Select all
]Find "('[^']*'|⍝.*$)?(?(-1)(*SKIP)(?!)|ABC)" -regex 

You can replace ABC by the regex of your choice.

Return to Language

Who is online

Users browsing this forum: No registered users and 1 guest