- Subject: Re: where is a description for use of regexp replace
- From: "John E. Davis" <davis>
- Date: Wed, 18 Dec 2002 11:22:41 -0500
Joachim Schmitz <js@xxxxxxxxxxxxx> wrote:
>So I have to replace all occurences such as:
>
><img src="images/keyvisual3" width="567" height="20">
>
>with
>
><img src="images/keyvisual3" width="567" height="20" />
Using the query_replace_match function, accessable via the
"Search->Regexp Replace" menu item (also as "ESC %" in emacs
bindings), enter
src="\([^>]+\)>
at the first prompt and
src="\1/>
at the second.
Note the occurance of \(...\) in the first expression. It defines a
group. That the characters in the group are represented by \1 in the
second expression. Unfortunately, this is yet another example of how
poorly documented jed is. The slang documentation for the
string_match_nth function is somewhat better:
string_match_nth
SYNOPSIS
Get the result of the last call to string_match
USAGE
(Integer_Type, Integer_Type) = string_match_nth(Integer_Type nth)
DESCRIPTION
The `string_match_nth' function returns two integers describing
the result of the last call to `string_match'. It returns both
the offset into the string and the length of characters matches by
the `nth' submatch.
By convention, `nth' equal to zero means the entire match.
Otherwise, `nth' must be an integer with a value 1 through 9,
and refers to the set of characters matched by the `nth' regular
expression enclosed by the pairs `\(, \)'.
EXAMPLE
Consider:
variable matched, pos, len;
matched = string_match("hello world", "\\([a-z]+\\) \\([a-z]+\\)", 1);
if (matched) (pos, len) = string_match_nth(2);
This will set `matched' to 1 since a match will be found at the
first position, `pos' to 6 since `w' is offset 6 characters
from the beginning of the string, and `len' to 5 since
`"world"' is 5 characters long.
NOTES
The position offset is _not_ affected by the value of the offset
parameter to the `string_match' function. For example, if the
value of the last parameter to the `string_match' function had
been 3, `pos' would still have been set to 6.
Note also that `string_match_nth' returns the _offset_ from
the beginning of the string and not the position of the match.
SEE ALSO
string_match
[Obtained from file /usr/local/doc/slang/slangfun.txt]
-----------------------------------
Good luck,
--John
--------------------------
To unsubscribe send email to <jed-users-request@xxxxxxxxxxx> with
the word "unsubscribe" in the message body.
Need help? Email <jed-users-owner@xxxxxxxxxxx>.
[2002 date index]
[2002 thread index]
[Thread Prev] [Thread Next]
[Date Prev] [Date Next]