土星五号 <laf...@gmail.com> writes:
> does emacs regular expression support (?!expression) ?
It would be more helpful if you'd tell us what (?!expression) would
match, preferably with some examples. Syntactically, emacs regexp's shy
groups look similar. The regular expression
"\\(:?foo\\|bar\\)\\([0-9]+\\)"
matches "foo19" or "bar23", but doesn't capture foo or bar, so that
(match-string 1) is the number.
Tassilo Horn <tass...@member.fsf.org> wrote:
>> does emacs regular expression support (?!expression) ?
> It would be more helpful if you'd tell us what (?!expression) would
> match, preferably with some examples. Syntactically, emacs regexp's shy
> groups look similar. The regular expression
> "\\(:?foo\\|bar\\)\\([0-9]+\\)"
> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
> (match-string 1) is the number.
In Perl, "(?!pattern)" is a zero-width negative look-ahead
assertion. Emacs does not support these AFAIK.
>> It would be more helpful if you'd tell us what (?!expression) would
>> match, preferably with some examples. Syntactically, emacs regexp's shy
>> groups look similar. The regular expression
>> "\\(:?foo\\|bar\\)\\([0-9]+\\)"
BTW, that should have been (?:...).
>> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
>> (match-string 1) is the number.
> In Perl, "(?!pattern)" is a zero-width negative look-ahead
> assertion. Emacs does not support these AFAIK.
I see. So when you do /foo(?!bar)/ in Perl, you'd need to do
"foo\\(?:[^b][^a][^r]\\)" in elisp.
Tassilo Horn <tass...@member.fsf.org> wrote:
> [...]
>>> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
>>> (match-string 1) is the number.
>> In Perl, "(?!pattern)" is a zero-width negative look-ahead
>> assertion. Emacs does not support these AFAIK.
> I see. So when you do /foo(?!bar)/ in Perl, you'd need to do
> "foo\\(?:[^b][^a][^r]\\)" in elisp.
You have to account for possible end-of-buffer as well so
usually it's "easier" to use two matches ('(while (and
(search-forward-regexp "foo") (not (looking-at "bar"))))'
(untested)) - that's why I (still :-)) think these features
should be implemented in Emacs as well.
I wrote:
>> [...]
>>>> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
>>>> (match-string 1) is the number.
>>> In Perl, "(?!pattern)" is a zero-width negative look-ahead
>>> assertion. Emacs does not support these AFAIK.
>> I see. So when you do /foo(?!bar)/ in Perl, you'd need to do
>> "foo\\(?:[^b][^a][^r]\\)" in elisp.
> You have to account for possible end-of-buffer as well so
> usually it's "easier" to use two matches ('(while (and
> (search-forward-regexp "foo") (not (looking-at "bar"))))'
> (untested)) - [...]
Eh, yes, there is an "(untested)", but still the logic is
obviously plain wrong. But you get the idea.
> Tim Landscheidt<t...@tim-landscheidt.de> writes:
>> In Perl, "(?!pattern)" is a zero-width negative look-ahead
>> assertion. Emacs does not support these AFAIK.
> I see. So when you do /foo(?!bar)/ in Perl, you'd need to do
> "foo\\(?:[^b][^a][^r]\\)" in elisp.
IIUC, the Perl regex would successfully match "foo" if it were followed by
"far", but the Emacs regexp would not.
Maybe \(?:[^b][^a][^r]\) should be \(?:[^b]\|b[^a]\|ba[^r]\)
I would like match Err in any words(e.g. LastError), but not ErrorMode.
(defvar txt-mode-font-lock-keywords
`(
;; 文件名
("\\\\\\(\\w+\\.exe\\)" 1 font-lock-keyword-face)
;; IP和版本
Thien-Thi Nguyen <t...@gnuvola.org> wrote:
> I would like match Err in any words(e.g. LastError), but not ErrorMode.
> ("\\([Ee][Rr][Rr]\\)\\(?!orMode\\)" 1 font-lock-warning-face)
> You can add a spec for ‘ErrorMode’, with default face, prior to this one.
Thien-Thi Nguyen <t...@gnuvola.org> wrote:
> > You can add a spec for ‘ErrorMode’, with default face, prior to this one.
> Which Emacs version does support that?
> Any that processes these specs in the given order, with
> "masking semantics", i suppose. (I haven't tried.)
>>>> matches "foo19" or "bar23", but doesn't capture foo or bar, so that
>>>> (match-string 1) is the number.
>>> In Perl, "(?!pattern)" is a zero-width negative look-ahead
>>> assertion. Emacs does not support these AFAIK.
>> I see. So when you do /foo(?!bar)/ in Perl, you'd need to do
>> "foo\\(?:[^b][^a][^r]\\)" in elisp.
>You have to account for possible end-of-buffer as well so
>usually it's "easier" to use two matches ('(while (and
>(search-forward-regexp "foo") (not (looking-at "bar"))))'
>(untested)) - that's why I (still :-)) think these features
>should be implemented in Emacs as well.
>Tim
And, by the above, that's not a "regexp" (emacs), but a bunch of
elisp code. Meaning that (as far as I know) you can't just
type it in, in response to a prompt-for-a-regexp, as you'd get
with a M-C s, query-replace-regexp, etc, but would have to --
well, what *would* you have to do for a M-C % -- you would have
to write a whole paragraph of elisp to duplicate what query-replace-regexp
does, somewhere inserting the above elisp that emulates the perl
regexp?
Easier to just get out of emacs for a bit, and do that perl-like
edit in perl itself?