* Re: Quickie - Regexp for a string not at the beginning of the line
2012-10-26 1:08 ` Quickie - Regexp for a string not at the beginning of the line Rivka Miller
@ 2012-10-26 2:00 ` Ed Morton
2012-10-26 2:11 ` Ben Bacarisse
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Ed Morton @ 2012-10-26 2:00 UTC (permalink / raw)
To: help-gnu-emacs
On 10/25/2012 8:08 PM, Rivka Miller wrote:
> On Oct 25, 2:27 pm, Danny <dann90...@gmail.com> wrote:
>> Why you just don't give us the string/input, say a line or two, and what you want off of it, so we can tell better what to suggest
>
> no one has really helped yet.
Because there is no solution - there IS no _RE_ that will match a string not at
the beginning of a line.
Now if you want to know how to extract a string that matches an RE in awk,
that'd be (just one way):
awk 'match($0,/.[$]hello[$]/) { print substr($0,RSTART+1,RLENGTH-1) }'
and other tools would have their ways of producing the same output, but that's
not the question you're asking.
Ed.
>
> I want to search and modify.
>
> I dont wanna be tied to a specific language etc so I just want a
> regexp and as many versions as possible. Maybe I should try in emacs
> and so I am now posting to emacs groups also, although javascript has
> rich set of regexp facilities.
>
> examples
>
> $hello$ should not be selected but
> not hello but all of the $hello$ and $hello$ ... $hello$ each one
> selected
>
> =================
> original post
> =================
>
>
> Hello Programmers,
>
> I am looking for a regexp for a string not at the beginning of the
> line.
>
> For example, I want to find $hello$ that does not occur at the
> beginning of the string, ie all $hello$ that exclude ^$hello$.
>
> In addition, if you have a more difficult problem along the same
> lines, I would appreciate it. For a single character, eg < not at the
> beginning of the line, it is easier, ie
>
> ^[^<]+<
>
> but I cant use the same method for more than one character string as
> permutation is present and probably for more than one occurrence,
> greedy or non-greedy version of [^<]+ would pick first or last but not
> the middle ones, unless I break the line as I go and use the non-
> greedy version of +. I do have the non-greedy version available, but
> what if I didnt?
>
> If you cannot solve the problem completely, just give me a quick
> solution with the first non beginning of the line and I will go from
> there as I need it in a hurry.
>
> Thanks
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Quickie - Regexp for a string not at the beginning of the line
2012-10-26 1:08 ` Quickie - Regexp for a string not at the beginning of the line Rivka Miller
2012-10-26 2:00 ` Ed Morton
@ 2012-10-26 2:11 ` Ben Bacarisse
2012-10-26 4:45 ` Rivka Miller
2012-10-26 2:19 ` PJ Weisberg
2012-10-26 3:22 ` anon
3 siblings, 1 reply; 9+ messages in thread
From: Ben Bacarisse @ 2012-10-26 2:11 UTC (permalink / raw)
To: help-gnu-emacs
Rivka Miller <rivkaumiller@gmail.com> writes:
> On Oct 25, 2:27 pm, Danny <dann90...@gmail.com> wrote:
>> Why you just don't give us the string/input, say a line or two, and
>> what you want off of it, so we can tell better what to suggest
>
> no one has really helped yet.
Really? I was going to reply but then I saw Janis had given you the
answer. If it's not the answer, you should just reply saying what it is
that's wrong with it.
> I want to search and modify.
Ah. That was missing from the original post. You can't expect people
to help with questions that weren't asked! To replace you will usually
have to capture the single preceding character. E.g. in sed:
sed -e 's/\(.\)$hello\$/\1XXX/'
but some RE engines (Perl's, for example) allow you specify zero-width
assertions. You could, in Perl, write
s/(?<=.)\$hello\$/XXX/
without having to capture whatever preceded the target string. But
since Perl also has negative zero-width look-behind you can code your
request even more directly:
s/(?<!^)\$hello\$/XXX/
> I dont wanna be tied to a specific language etc so I just want a
> regexp and as many versions as possible. Maybe I should try in emacs
> and so I am now posting to emacs groups also, although javascript has
> rich set of regexp facilities.
You can't always have a universal solution because different PE
implementations have different syntax and semantics, but you should be
able to translate Janis's solution of matching *something* before your
target into every RE implementation around.
> examples
>
> $hello$ should not be selected but
> not hello but all of the $hello$ and $hello$ ... $hello$ each one
> selected
I have taken your $s to be literal. That's not 100 obvious since $ is a
common (universal?) RE meta-character.
<snip>
--
Ben.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Quickie - Regexp for a string not at the beginning of the line
2012-10-26 2:11 ` Ben Bacarisse
@ 2012-10-26 4:45 ` Rivka Miller
2012-10-26 12:11 ` Ben Bacarisse
2012-10-26 12:32 ` Ed Morton
0 siblings, 2 replies; 9+ messages in thread
From: Rivka Miller @ 2012-10-26 4:45 UTC (permalink / raw)
To: help-gnu-emacs
Thanks everyone, esp this gentleman.
The solution that worked best for me is just to use a DOT before the
string as the one at the beginning of the line did not have any char
before it. I guess, this requires the ability to ignore the CARAT as
the beginning of the line.
I am a satisfied custormer. No need for returns. :)
On Oct 25, 7:11 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
> Rivka Miller <rivkaumil...@gmail.com> writes:
> > On Oct 25, 2:27 pm, Danny <dann90...@gmail.com> wrote:
> >> Why you just don't give us the string/input, say a line or two, and
> >> what you want off of it, so we can tell better what to suggest
>
> > no one has really helped yet.
>
> Really? I was going to reply but then I saw Janis had given you the
> answer. If it's not the answer, you should just reply saying what it is
> that's wrong with it.
>
> > I want to search and modify.
>
> Ah. That was missing from the original post. You can't expect people
> to help with questions that weren't asked! To replace you will usually
> have to capture the single preceding character. E.g. in sed:
>
> sed -e 's/\(.\)$hello\$/\1XXX/'
>
> but some RE engines (Perl's, for example) allow you specify zero-width
> assertions. You could, in Perl, write
>
> s/(?<=.)\$hello\$/XXX/
>
> without having to capture whatever preceded the target string. But
> since Perl also has negative zero-width look-behind you can code your
> request even more directly:
>
> s/(?<!^)\$hello\$/XXX/
>
> > I dont wanna be tied to a specific language etc so I just want a
> > regexp and as many versions as possible. Maybe I should try in emacs
> > and so I am now posting to emacs groups also, although javascript has
> > rich set of regexp facilities.
>
> You can't always have a universal solution because different PE
> implementations have different syntax and semantics, but you should be
> able to translate Janis's solution of matching *something* before your
> target into every RE implementation around.
>
> > examples
>
> > $hello$ should not be selected but
> > not hello but all of the $hello$ and $hello$ ... $hello$ each one
> > selected
>
> I have taken your $s to be literal. That's not 100 obvious since $ is a
> common (universal?) RE meta-character.
>
> <snip>
> --
> Ben.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Quickie - Regexp for a string not at the beginning of the line
2012-10-26 4:45 ` Rivka Miller
@ 2012-10-26 12:11 ` Ben Bacarisse
2012-10-26 12:32 ` Ed Morton
1 sibling, 0 replies; 9+ messages in thread
From: Ben Bacarisse @ 2012-10-26 12:11 UTC (permalink / raw)
To: help-gnu-emacs
Rivka Miller <rivkaumiller@gmail.com> writes:
> Thanks everyone, esp this gentleman.
Kind of you to single me out, but it was Janis Papanagnou who first
posted the solution that you say "works best" for you.
<snip>
--
Ben.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Quickie - Regexp for a string not at the beginning of the line
2012-10-26 4:45 ` Rivka Miller
2012-10-26 12:11 ` Ben Bacarisse
@ 2012-10-26 12:32 ` Ed Morton
1 sibling, 0 replies; 9+ messages in thread
From: Ed Morton @ 2012-10-26 12:32 UTC (permalink / raw)
To: help-gnu-emacs
On 10/25/2012 11:45 PM, Rivka Miller wrote:
> Thanks everyone, esp this gentleman.
>
> The solution that worked best for me is just to use a DOT before the
> string as the one at the beginning of the line did not have any char
> before it.
That's fine but do you understand that that is not an RE that matches on
"$hello$ not at the start of a line", it's an RE that matches on "<any
char>$hello$ anywhere in the line"? There's a difference - if you use a tool
that prints the text that matches an RE then the output if the first RE existed
would be "$hello$" while the output for the second RE would be "X$hello$" or
"Y$hello$" or....
In some tools you can use /(.)$hello$/ or similar to ignore the first part of
the RE "(.)" and just print the second "$hello", but that ability and it's
syntax is tool-specific, you still can't say "here's an RE that does this",
you've got to say "here's how to find this text using tool <whatever>".
Ed.
> I guess, this requires the ability to ignore the CARAT as the beginning of the line.
>
> I am a satisfied custormer. No need for returns. :)
>
> On Oct 25, 7:11 pm, Ben Bacarisse <ben.use...@bsb.me.uk> wrote:
>> Rivka Miller <rivkaumil...@gmail.com> writes:
>>> On Oct 25, 2:27 pm, Danny <dann90...@gmail.com> wrote:
>>>> Why you just don't give us the string/input, say a line or two, and
>>>> what you want off of it, so we can tell better what to suggest
>>
>>> no one has really helped yet.
>>
>> Really? I was going to reply but then I saw Janis had given you the
>> answer. If it's not the answer, you should just reply saying what it is
>> that's wrong with it.
>>
>>> I want to search and modify.
>>
>> Ah. That was missing from the original post. You can't expect people
>> to help with questions that weren't asked! To replace you will usually
>> have to capture the single preceding character. E.g. in sed:
>>
>> sed -e 's/\(.\)$hello\$/\1XXX/'
>>
>> but some RE engines (Perl's, for example) allow you specify zero-width
>> assertions. You could, in Perl, write
>>
>> s/(?<=.)\$hello\$/XXX/
>>
>> without having to capture whatever preceded the target string. But
>> since Perl also has negative zero-width look-behind you can code your
>> request even more directly:
>>
>> s/(?<!^)\$hello\$/XXX/
>>
>>> I dont wanna be tied to a specific language etc so I just want a
>>> regexp and as many versions as possible. Maybe I should try in emacs
>>> and so I am now posting to emacs groups also, although javascript has
>>> rich set of regexp facilities.
>>
>> You can't always have a universal solution because different PE
>> implementations have different syntax and semantics, but you should be
>> able to translate Janis's solution of matching *something* before your
>> target into every RE implementation around.
>>
>>> examples
>>
>>> $hello$ should not be selected but
>>> not hello but all of the $hello$ and $hello$ ... $hello$ each one
>>> selected
>>
>> I have taken your $s to be literal. That's not 100 obvious since $ is a
>> common (universal?) RE meta-character.
>>
>> <snip>
>> --
>> Ben.
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Quickie - Regexp for a string not at the beginning of the line
2012-10-26 1:08 ` Quickie - Regexp for a string not at the beginning of the line Rivka Miller
2012-10-26 2:00 ` Ed Morton
2012-10-26 2:11 ` Ben Bacarisse
@ 2012-10-26 2:19 ` PJ Weisberg
2012-10-26 12:02 ` Doug Lewan
2012-10-26 3:22 ` anon
3 siblings, 1 reply; 9+ messages in thread
From: PJ Weisberg @ 2012-10-26 2:19 UTC (permalink / raw)
To: Rivka Miller; +Cc: help-gnu-emacs@gnu.org
[-- Attachment #1: Type: text/plain, Size: 476 bytes --]
On Thursday, October 25, 2012, Rivka Miller <rivkaumiller@gmail.com> wrote:
> Hello Programmers,
>
> I am looking for a regexp for a string not at the beginning of the
> line.
>
> For example, I want to find $hello$ that does not occur at the
> beginning of the string, ie all $hello$ that exclude ^$hello$.
How about a zero-width lookbehind for any character?
--
-PJ
Gehm's Corollary to Clark's Law: Any technology distinguishable from
magic is insufficiently advanced.
[-- Attachment #2: Type: text/html, Size: 609 bytes --]
^ permalink raw reply [flat|nested] 9+ messages in thread
* RE: Quickie - Regexp for a string not at the beginning of the line
2012-10-26 2:19 ` PJ Weisberg
@ 2012-10-26 12:02 ` Doug Lewan
0 siblings, 0 replies; 9+ messages in thread
From: Doug Lewan @ 2012-10-26 12:02 UTC (permalink / raw)
To: Rivka Miller; +Cc: help-gnu-emacs@gnu.org
Or simply make sure the RE that you're using has an [uninteresting] character before the [interesting] part.
v
(while (re-search-forward ".\\(interesting\\)+" (point-max) t)
(replace-match "MORE interesting" t t nil 1))
I hope this helps.
From: help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org [mailto:help-gnu-emacs-bounces+dougl=shubertticketing.com@gnu.org] On Behalf Of PJ Weisberg
Sent: Thursday, 2012 October 25 22:19
To: Rivka Miller
Cc: help-gnu-emacs@gnu.org
Subject: Re: Quickie - Regexp for a string not at the beginning of the line
On Thursday, October 25, 2012, Rivka Miller <rivkaumiller@gmail.com> wrote:
> Hello Programmers,
>
> I am looking for a regexp for a string not at the beginning of the
> line.
>
> For example, I want to find $hello$ that does not occur at the
> beginning of the string, ie all $hello$ that exclude ^$hello$.
How about a zero-width lookbehind for any character?
--
-PJ
Gehm's Corollary to Clark's Law: Any technology distinguishable from
magic is insufficiently advanced.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Quickie - Regexp for a string not at the beginning of the line
2012-10-26 1:08 ` Quickie - Regexp for a string not at the beginning of the line Rivka Miller
` (2 preceding siblings ...)
2012-10-26 2:19 ` PJ Weisberg
@ 2012-10-26 3:22 ` anon
3 siblings, 0 replies; 9+ messages in thread
From: anon @ 2012-10-26 3:22 UTC (permalink / raw)
To: help-gnu-emacs
On Thu, 25 Oct 2012 18:08:53 -0700 (PDT), Rivka Miller
<rivkaumiller@gmail.com> wrote in
<73f60cf3-d932-4366-a405-6767488560c6@q16g2000yqc.googlegroups.com>:
>no one has really helped yet.
We regret that you are not a satisfied customer.
Please take your receipt to the cashier and you will receive double your
money back according to our "you must be satisfied" guarantee.
^ permalink raw reply [flat|nested] 9+ messages in thread