* regexp problem
@ 2006-08-12 3:33 Þorne
2006-08-12 3:56 ` Pascal Bourguignon
0 siblings, 1 reply; 5+ messages in thread
From: Þorne @ 2006-08-12 3:33 UTC (permalink / raw)
Is there a way to match only `b' if and only if it appears in the
context `abc' ?
So searching `foo abc b ' would return a match of `b' but `bar xbc'
would not return any matches.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: regexp problem
2006-08-12 3:33 regexp problem Þorne
@ 2006-08-12 3:56 ` Pascal Bourguignon
2006-08-12 9:46 ` Þorne
0 siblings, 1 reply; 5+ messages in thread
From: Pascal Bourguignon @ 2006-08-12 3:56 UTC (permalink / raw)
"Þorne" <ego111@gmail.com> writes:
> Is there a way to match only `b' if and only if it appears in the
> context `abc' ?
>
> So searching `foo abc b ' would return a match of `b' but `bar xbc'
> would not return any matches.
You can match groups:
a\(b\)c
so the match number 0 is the whole regexp: abc
but the match number 1 is only b
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Debugging? Klingons do not debug! Our software does not coddle the
weak."
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: regexp problem
2006-08-12 3:56 ` Pascal Bourguignon
@ 2006-08-12 9:46 ` Þorne
2006-08-12 10:12 ` Pascal Bourguignon
0 siblings, 1 reply; 5+ messages in thread
From: Þorne @ 2006-08-12 9:46 UTC (permalink / raw)
Pascal Bourguignon wrote:
> You can match groups:
>
> a\(b\)c
>
> so the match number 0 is the whole regexp: abc
> but the match number 1 is only b
Sorry to be dense, but do you mean something like this:
(search-forward-regexp "a\\(b\\)c\\0")
because i can't get anything like it to work. I don't really follow
the documentation for the \<digit> construct in regexps at all...
In fact the code above finds a string that looks like `abc0' instead of
just `b'.
Specifically i am trying to make a regexp for define-generic-mode to
colorize the string`*' but only if it is in a string that looks like
`(*)'. But not colorize the surrounding parens.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: regexp problem
2006-08-12 9:46 ` Þorne
@ 2006-08-12 10:12 ` Pascal Bourguignon
2006-08-12 11:02 ` Þorne
0 siblings, 1 reply; 5+ messages in thread
From: Pascal Bourguignon @ 2006-08-12 10:12 UTC (permalink / raw)
"Þorne" <ego111@gmail.com> writes:
> Pascal Bourguignon wrote:
>> You can match groups:
>>
>> a\(b\)c
>>
>> so the match number 0 is the whole regexp: abc
>> but the match number 1 is only b
>
> Sorry to be dense, but do you mean something like this:
>
> (search-forward-regexp "a\\(b\\)c\\0")
(when (search-forward-regexp "a\\(b\\)c")
(let ((all (match-string 0))
(only-b (match-string 1)))
(goto-char (match-end 0))
(insert (format "\nall = %s\nonly-b = %s\n" all only-b))))
> because i can't get anything like it to work. I don't really follow
> the documentation for the \<digit> construct in regexps at all...
>
> In fact the code above finds a string that looks like `abc0' instead of
> just `b'.
>
> Specifically i am trying to make a regexp for define-generic-mode to
> colorize the string`*' but only if it is in a string that looks like
> `(*)'. But not colorize the surrounding parens.
Read with utmost attention the help about the variable font-lock-keywords.
(MATCHER . SUBEXP)
("fu\\(bar\\)" . 1) substring "bar" within all occurrences of "fubar" in
the value of `font-lock-keyword-face'.
--
__Pascal Bourguignon__ http://www.informatimago.com/
COMPONENT EQUIVALENCY NOTICE: The subatomic particles (electrons,
protons, etc.) comprising this product are exactly the same in every
measurable respect as those used in the products of other
manufacturers, and no claim to the contrary may legitimately be
expressed or implied.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: regexp problem
2006-08-12 10:12 ` Pascal Bourguignon
@ 2006-08-12 11:02 ` Þorne
0 siblings, 0 replies; 5+ messages in thread
From: Þorne @ 2006-08-12 11:02 UTC (permalink / raw)
Pascal Bourguignon wrote:
> "Þorne" <ego111@gmail.com> writes:
>
> > Pascal Bourguignon wrote:
> >> You can match groups:
> >>
> >> a\(b\)c
> >>
> >> so the match number 0 is the whole regexp: abc
> >> but the match number 1 is only b
> >
> > Sorry to be dense, but do you mean something like this:
> >
> > (search-forward-regexp "a\\(b\\)c\\0")
>
>
> (when (search-forward-regexp "a\\(b\\)c")
> (let ((all (match-string 0))
> (only-b (match-string 1)))
> (goto-char (match-end 0))
> (insert (format "\nall = %s\nonly-b = %s\n" all only-b))))
>
>
>
> > because i can't get anything like it to work. I don't really follow
> > the documentation for the \<digit> construct in regexps at all...
> >
> > In fact the code above finds a string that looks like `abc0' instead of
> > just `b'.
> >
> > Specifically i am trying to make a regexp for define-generic-mode to
> > colorize the string`*' but only if it is in a string that looks like
> > `(*)'. But not colorize the surrounding parens.
>
> Read with utmost attention the help about the variable font-lock-keywords.
>
> (MATCHER . SUBEXP)
>
> ("fu\\(bar\\)" . 1) substring "bar" within all occurrences of "fubar" in
> the value of `font-lock-keyword-face'.
Ah! Thank you! Got it finally.
(Turned out specifically what i needed for doing it (with
font-lock-type-face in my case) was:
(define-generic-mode 'foo
nil nil
(list
blah-blah
'("(\\(\\*\\))" 1 font-lock-type-face))
blah-blah))
Thanks again!
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2006-08-12 11:02 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-08-12 3:33 regexp problem Þorne
2006-08-12 3:56 ` Pascal Bourguignon
2006-08-12 9:46 ` Þorne
2006-08-12 10:12 ` Pascal Bourguignon
2006-08-12 11:02 ` Þorne
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.