Lugaru's Epsilon
Programmer's
Editor 14.04

Context:
Epsilon User's Manual and Reference
   Commands by Topic
      Changing Text
         . . .
         Replacing
         Regular Expressions
            . . .
            Regular Expression Examples
            Searching Rules
            Regular Expression Assertions
            Regular Expression Commands
         Rearranging
            Sorting
            Comparing By Lines
            Transposing
            Formatting Text
         . . .

Previous   Up    Next
Searching Rules  Commands by Topic   Regular Expression Commands


Epsilon User's Manual and Reference > Commands by Topic > Changing Text > Regular Expressions >

Regular Expression Assertions

You can force Epsilon to reject any potential match that does not line up appropriately with a line boundary, by using the "^" and "$" assertions. A "^" assertion specifies a beginning-of-line match, and a "$" assertion specifies an end-of-line match. For example, if you search for ^new|waste in the following line, it would match the indicated section:

And with old woes new wail my dear times's waste;

Even though the word "new" occurs before "waste", it does not appear at the beginning of the line, so Epsilon rejects it.

Other assertions use Epsilon's angle-bracket syntax. Like the assertions ^ and $, these don't match any specific characters, but a potential match will be rejected if the assertion isn't true at that point in the pattern.

 Assertion  Meaning
 ^  At the start of a line.
 $  At the end of a line.
 <bob> or <bof>  At the start of the buffer.
 <eob> or <eof>  At the end of the buffer.

For example, searching for <bob>sometext<eob> won't succeed unless the buffer contains only the eight character string sometext.

You can create new assertions from character classes specified with the angle bracket syntax by adding [, ] or / at the start of the pattern.

 Assertion  Meaning
 <[class>  The next character matches class, the previous one does not.
 <]class>  The previous character matches class, the next one does not.
 </class>  Either of the above.

The class in the above syntax is a |-separated or &-separated list of one or more single characters, character names like Space or Tab, character numbers like #32 or #9, ranges of any of these, character class names like Word or Digit, or Unicode property specifications. See Character Classes for details on character classes.

For example, </word> matches at a word boundary, and <]word> matches at the end of a word. The pattern <]0-9|a-f> matches at the end of a run of hexadecimal digits. The pattern (cat|[0-9])</digit>(dog|[0-9]) matches cat3 or 4dog, but not catdog or 42. The pattern <[p:cyrillic> matches at the start of a run of Cyrillic characters.

Color Class Assertions

Another type of assertion matches based on the next character's color class for syntax highlighting. <^c:*comment>printf finds uses of printf that aren't commented out. <[c:perl-string>" finds " characters that start a string in Perl mode, ignoring those that end it, or appear quoted inside it, or in comments or other places.

The text after the c: is a simple filename-style pattern that will be matched against the name of the color class: * matches zero or more characters, ? matches any single character, and simple ranges with [] are allowed. A character with no syntax highlighting applied will match the name "none". This type of assertion may start with ^ to invert the matching rules, or with /, [ or ] to match color boundaries.

To apply more than one assertion to a character, put them in sequence. <^c:perl-string><^c:*comment>printf finds instances of printf that are in neither Perl strings nor comments.

You can use the set-color command to see the color class names Epsilon uses.

When you combine assertions with operators * or +, you must use parentheses to specify that the assertion applies to each character. (<^c:*-comment><any>)+ matches a run of non-comment characters. Without the parentheses the assertion only applies to the first character of the run.

In extension language code, use the do_color_searching( ) subroutine if your regular expression might include syntax highlighting assertions, which ensures the buffer's syntax highlighting is up to date.



Previous   Up    Next
Searching Rules  Commands by Topic   Regular Expression Commands


Lugaru Epsilon Programmer's Editor 14.04 manual. Copyright (C) 1984, 2021 by Lugaru Software Ltd. All rights reserved.