faqts : Computers : Programming : Languages : Tse : Search

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 3 people (33%) answered Yes
Recently 1 of 3 people (33%) answered Yes

Entry

TSE: File: Search/Replace: Regular expression: Does a regular expression search span multiple lines?

Aug 26th, 2005 16:18
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 19 December 2004 - 11:42 pm -------------------

TSE: File: Search/Replace: Regular expression: Does a regular 
expression search span multiple lines?

---

Yes, in some cases the TSE the regular expression
search or replace will span multiple lines.

---

In other cases they will stop at e.g. the end of the
first line.

This because matches might include an empty string.

---
---

Using e.g. the regular expression operators:

 + (1 or more times, minimum closure)

 # (1 or more times, maximum closure)

 * (0 or more times, minimum closure)

 @ (0 or more times, maximum closure)

---

e.g.

LFind( ".@", "glx" )

will only search in the current line of a highlighted block, and not in
multiple lines.

This because '@' also matches an empty string.

---
---

Workaround:

1. Do not search with regular expressions,
   but search without the 'x' option.

   e.g.

    LFind( "a", "" )

   searches for the character 'a', even over multiple lines

   ---

   Note:

   You can then e.g. store the x-y coordinates
   of the begin and end position to mark
   a block

2. Use the CurrChar() in combination with
   the NextChar() or PrevChar()
   commands, as these last 2 commands can traverse
   to the next or previous line

3. Use another regular expression
   (use e.g. the 'not' class [~...])

4. Other

---
---

E.g. to skip spaces over several lines:

--- cut here: begin --------------------------------------------------

 WHILE ( CurrChar() == Asc( " " ) OR ( CurrChar() == _AT_EOL_ ) OR (
CurrChar() == _BEYOND_EOL_ ) ) // skip spaces and go pass end of line

  NextChar()

 ENDWHILE

--- cut here: end ----------------------------------------------------

If you should use here a regular expression using the '@' operator,
it will only works on the current line, but not over multiple lines.

--- cut here: begin --------------------------------------------------

 LFind( "[ ]@\c", "xl" ) // skip spaces in highlighted block

--- cut here: end ----------------------------------------------------

But there are other possible regular expressions that do work over
multiple lines. Here you use e.g. the while 'not' found a space,
continue to search:

--- cut here: begin --------------------------------------------------

 LFind( "[~ ]", "x" ) // skip spaces in highlighted block, also over
multiple lines

// with thanks to Carlo Hogeveen

--- cut here: end ----------------------------------------------------

---
---

Internet: see also:

---

TSE: File: Search: How to search/replace over multiple lines? 
[dehyphenation / regular expression]
http://www.faqts.com/knowledge_base/view.phtml/aid/36302/fid/865

---

TSE: Search/Replace: Regular expression: Link: Can you give overview
links regular expressions?
http://www.faqts.com/knowledge_base/view.phtml/aid/31433/fid/865

----------------------------------------------------------------------