| Cobra | Interactive Query Language | text patterns | ||
|---|---|---|---|---|
| NAMEtext patterns and regular expressionsSYNTAXp_expr: (expr) | /regex expr: ( expr ) | expr binop expr | unop expr | const_expr | tokref | name const_expr: size nr | nr regex: [-^$\[\]a-zA-Z0-9_]+ binop: + | - | * | / | % | > | >= | < | <= | == | != | && | || | & | \| unop: ! | - tokref: .bracket # nesting level of square brackets .curly # nesting level of curly braces .fct # function name (or "global") .fnm # filename .len # length of the token text .lnr # line number .mark # current value of token mark .range # length in lines of an associated range, or -1 .round # nesting level of parentheses .seq # internal sequence nr of the token name [a-bA-Z][a-zA-Z0-9_]+ DESCRIPTIONThis page described textual patterns for use in mark commands. For the more general pattern-search expressions, used with a pat or pe command, see pe.
All Cobra commands that accept pattern arguments (e.g., mark, contains, extend, stretch, etc.)
can take either a regular expression, or a pattern expression enclosed in round braces as an argument.
 EXAMPLES: m /. # mark all tokens (using a regex that matches anything) : m /> # mark all tokens that contain > in the text, e.g., -> : m /^[<>]$ # mark tokens that match > or < : m & (.lnr > 10 && .lnr < 100) # keep only those for source lines 10..100 : reset : m @ident # mark all identifiers : m & (.len > 32) # keep only those longer than 32 characters : >2 # save marks in set 1 : m & (size(2) > 100) # preserve marks only if there are more than 100 marks in set 2 : m & (.fnm == "cobra.h") # can use either == or != for .fnm : m & (.fnm == /.h$) # match only in filenames ending in .h (no quotes needed)A typical use might be: : m \; # select all statement separators : s \; # attach a range from each mark upto the next statement separator : m & (.round == 0) # exclude sequences inside (...), ie for-stmnts : m & (.range == 0) # match only ranges on a single line : m & (.fnm == /^foo) # and only for file-names that start with "foo"More examples: : m & @str # keep match only if the type is string : m & /^nfm # keep match only if the text starts with nfm : m & (.fnm == /^nfm) # keep match only for filenames starting with nfm : # there can only be one regular expression per constraint, so this works: : m & (.fnm == /^pref && .curly > 0) : # but this does not: : m & (.fnm == /^pref1 || .fnm == /^pref2 ) SEE ALSOcontains, extend, back, mark, next, pe/pat, stretch, | ||||
| Return to index Manual Tutorial | (Last Updated: 14 May 2019) | |||