Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #32163 > unrolled thread

Quickie - Regexp for a string not at the beginning of the line

Started byRivka Miller <rivkaumiller@gmail.com>
First post2012-10-25 13:53 -0700
Last post2012-10-26 03:46 -0700
Articles 18 — 13 participants

Back to article view | Back to comp.lang.python


Contents

  Quickie - Regexp for a string not at the beginning of the line Rivka Miller <rivkaumiller@gmail.com> - 2012-10-25 13:53 -0700
    Re: Quickie - Regexp for a string not at the beginning of the line Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-10-25 23:01 +0200
    Re: Quickie - Regexp for a string not at the beginning of the line Zero Piraeus <schesis@gmail.com> - 2012-10-25 17:21 -0400
    Re: Quickie - Regexp for a string not at the beginning of the line Rivka Miller <rivkaumiller@gmail.com> - 2012-10-25 18:08 -0700
      Re: Quickie - Regexp for a string not at the beginning of the line Dave Angel <d@davea.name> - 2012-10-25 21:21 -0400
      Re: Quickie - Regexp for a string not at the beginning of the line Ed Morton <mortonspam@gmail.com> - 2012-10-25 21:00 -0500
        Re: Quickie - Regexp for a string not at the beginning of the line Devin Jeanpierre <jeanpierreda@gmail.com> - 2012-10-26 01:08 -0400
      Re: Quickie - Regexp for a string not at the beginning of the line Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-26 03:11 +0100
        Re: Quickie - Regexp for a string not at the beginning of the line Rivka Miller <rivkaumiller@gmail.com> - 2012-10-25 21:45 -0700
          Re: Quickie - Regexp for a string not at the beginning of the line Janis Papanagnou <janis_papanagnou@hotmail.com> - 2012-10-26 11:18 +0200
          Re: Quickie - Regexp for a string not at the beginning of the line Ben Bacarisse <ben.usenet@bsb.me.uk> - 2012-10-26 13:11 +0100
          Re: Quickie - Regexp for a string not at the beginning of the line Ed Morton <mortonspam@gmail.com> - 2012-10-26 07:32 -0500
            Re: Quickie - Regexp for a string not at the beginning of the line Joel Goldstick <joel.goldstick@gmail.com> - 2012-10-26 08:53 -0400
      Re: Quickie - Regexp for a string not at the beginning of the line MRAB <python@mrabarnett.plus.com> - 2012-10-26 03:11 +0100
      Re: Quickie - Regexp for a string not at the beginning of the line David Hutto <dwightdhutto@gmail.com> - 2012-10-25 23:02 -0400
      Re: Quickie - Regexp for a string not at the beginning of the line anon@anon.anon - 2012-10-25 23:22 -0400
    Re: Quickie - Regexp for a string not at the beginning of the line Mark Lawrence <breamoreboy@yahoo.co.uk> - 2012-10-26 03:37 +0100
    Re: Quickie - Regexp for a string not at the beginning of the line Asen Bozhilov <asen.bozhilov@gmail.com> - 2012-10-26 03:46 -0700

#32163 — Quickie - Regexp for a string not at the beginning of the line

FromRivka Miller <rivkaumiller@gmail.com>
Date2012-10-25 13:53 -0700
SubjectQuickie - Regexp for a string not at the beginning of the line
Message-ID<9eba5652-f814-41fa-83e4-460bca2be264@n16g2000yqi.googlegroups.com>
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

[toc] | [next] | [standalone]


#32165

FromJanis Papanagnou <janis_papanagnou@hotmail.com>
Date2012-10-25 23:01 +0200
Message-ID<k6c9bj$bk9$1@news.m-online.net>
In reply to#32163
On 25.10.2012 22:53, Rivka Miller 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$.

   .hello

The dot represents any character. But for specific strings that
needs adjustments (e.g. looking for hh not at the beginning of a
line would require something like ^[^h]+hh - ah, well, you wrote
something similar below).

Janis

> 
> 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
> 
> 

[toc] | [prev] | [next] | [standalone]


#32168

FromZero Piraeus <schesis@gmail.com>
Date2012-10-25 17:21 -0400
Message-ID<mailman.2868.1351200115.27098.python-list@python.org>
In reply to#32163
:

On 25 October 2012 16:53, Rivka Miller <rivkaumiller@gmail.com> wrote:
> I am looking for a regexp for a string not at the beginning of the
> line.

There are probably quite a few ways to do this, but '(?<!^)PATTERN'
has the advantage of explicitly describing what you're trying to do.
For instance:

>>> pattern = re.compile(r"(?<!^)\b\w+\b")
>>> re.findall(pattern, "this is some text")
['is', 'some', 'text']

 -[]z.

[toc] | [prev] | [next] | [standalone]


#32174

FromRivka Miller <rivkaumiller@gmail.com>
Date2012-10-25 18:08 -0700
Message-ID<73f60cf3-d932-4366-a405-6767488560c6@q16g2000yqc.googlegroups.com>
In reply to#32163
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.

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

[toc] | [prev] | [next] | [standalone]


#32175

FromDave Angel <d@davea.name>
Date2012-10-25 21:21 -0400
Message-ID<mailman.2872.1351214544.27098.python-list@python.org>
In reply to#32174
On 10/25/2012 09: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.
>
> <SNIP>
>
> first non beginning of the line and I will go from
> there as I need it in a hurry.
>
>

Call a tow truck and tell him to jump your spare tire from his left turn
signal.  That'll be about as effective.  But crying wolf to several
towns at once is probably a mistake.

-- 

DaveA

[toc] | [prev] | [next] | [standalone]


#32177

FromEd Morton <mortonspam@gmail.com>
Date2012-10-25 21:00 -0500
Message-ID<k6cqs1$efg$1@dont-email.me>
In reply to#32174
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
>

[toc] | [prev] | [next] | [standalone]


#32193

FromDevin Jeanpierre <jeanpierreda@gmail.com>
Date2012-10-26 01:08 -0400
Message-ID<mailman.2882.1351228128.27098.python-list@python.org>
In reply to#32177
On Thu, Oct 25, 2012 at 10:00 PM, Ed Morton <mortonspam@gmail.com> wrote:
> Because there is no solution - there IS no _RE_ that will match a string not
> at the beginning of a line.

Depending on what the OP meant, the following would both work:

- r"^(?!mystring)" (the string does not occur at the beginning)
- r"(?!^)mystring" (the string occurs elsewhere than the beginning)
  [Someone else's interpretation]

Both are "regular expressions" even in the academic sense, or else
have a translation as regular expressions in the academic sense.
They're also Python regexps. So I don't know what you mean.

-- Devin

[toc] | [prev] | [next] | [standalone]


#32179

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-10-26 03:11 +0100
Message-ID<0.485c579271f72431d3a7.20121026031110BST.87k3ue7zk1.fsf@bsb.me.uk>
In reply to#32174
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.

[toc] | [prev] | [next] | [standalone]


#32192

FromRivka Miller <rivkaumiller@gmail.com>
Date2012-10-25 21:45 -0700
Message-ID<d243ac78-ffca-4e93-b2dc-6b30ca7d2586@r6g2000yqd.googlegroups.com>
In reply to#32179
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.

[toc] | [prev] | [next] | [standalone]


#32203

FromJanis Papanagnou <janis_papanagnou@hotmail.com>
Date2012-10-26 11:18 +0200
Message-ID<k6dkhb$4uk$3@speranza.aioe.org>
In reply to#32192
Am 26.10.2012 06:45, schrieb Rivka Miller:
> Thanks everyone, esp this gentleman.

Who is "this"?

>
> 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.

Which was what I suggested, and where you rudely answered...

> no one has really helped yet.

And obviously...

> I am a satisfied custormer.

...your perception about yourself and about the role of us
Usenet posters seems also not be very sane. Good luck.

[toc] | [prev] | [next] | [standalone]


#32212

FromBen Bacarisse <ben.usenet@bsb.me.uk>
Date2012-10-26 13:11 +0100
Message-ID<0.dea0cf42f0d760648f68.20121026131156BST.8739118mb7.fsf@bsb.me.uk>
In reply to#32192
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.

[toc] | [prev] | [next] | [standalone]


#32213

FromEd Morton <mortonspam@gmail.com>
Date2012-10-26 07:32 -0500
Message-ID<k6dvsb$sve$1@dont-email.me>
In reply to#32192
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.
>

[toc] | [prev] | [next] | [standalone]


#32214

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2012-10-26 08:53 -0400
Message-ID<mailman.2891.1351256027.27098.python-list@python.org>
In reply to#32213
On Fri, Oct 26, 2012 at 8:32 AM, Ed Morton <mortonspam@gmail.com> wrote:
> 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.
>>
>>
>
> --
> http://mail.python.org/mailman/listinfo/python-list

I would use str.find('your string')

It returns -1 if not found, and the index if it finds it.

why use regex for this?

-- 
Joel Goldstick

[toc] | [prev] | [next] | [standalone]


#32180

FromMRAB <python@mrabarnett.plus.com>
Date2012-10-26 03:11 +0100
Message-ID<mailman.2874.1351217512.27098.python-list@python.org>
In reply to#32174
On 2012-10-26 02:08, 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.
>
> 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
>
[snip]
To match the literal "$hello$" except at the start of a line, use:

(?<!^)\$hello\$

with the multiline flag set. You could set the multiline flag within
the regex like this:

(?m)(?<!^)\$hello\$

re.search will find the first occurrence. In order to find all such
occurrences in Python, you need to use re.findall or re.finditer.
(Other languages have their own ways.)

Note that there are different 'flavours' of regex, the most common form
following the lead of Perl, and that implementations might differ in
which features they support.

[toc] | [prev] | [next] | [standalone]


#32188

FromDavid Hutto <dwightdhutto@gmail.com>
Date2012-10-25 23:02 -0400
Message-ID<mailman.2879.1351220534.27098.python-list@python.org>
In reply to#32174
On Thu, Oct 25, 2012 at 9:08 PM, Rivka Miller <rivkaumiller@gmail.com> 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.
>
> 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.

If you just find the one command line app that will perform the task,
like awk, then the other languages you will just need to call the
commandline function, and return the output from awk.


-- 
Best Regards,
David Hutto
CEO: http://www.hitwebdevelopment.com

[toc] | [prev] | [next] | [standalone]


#32190

Fromanon@anon.anon
Date2012-10-25 23:22 -0400
Message-ID<jc0k889b366gubg5o8b1ucnloocf3gqv6n@4ax.com>
In reply to#32174
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.

[toc] | [prev] | [next] | [standalone]


#32186

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2012-10-26 03:37 +0100
Message-ID<mailman.2878.1351218871.27098.python-list@python.org>
In reply to#32163
On 25/10/2012 21:53, Rivka Miller wrote:
> Hello Programmers,
>
> I am looking for a regexp for a string not at the beginning of the
> line.
>

Why bother with a silly regex thingy when simple string methods will 
suffice e.g.

'yourstring'.find('xyz', 1)

or

'yourstring'.index('xyz', 1)

or

'xyz' in 'yourstring'[1:]

-- 
Cheers.

Mark Lawrence.

[toc] | [prev] | [next] | [standalone]


#32208

FromAsen Bozhilov <asen.bozhilov@gmail.com>
Date2012-10-26 03:46 -0700
Message-ID<e6119ead-c346-4429-9b8f-8b0c5ce974df@l7g2000vbj.googlegroups.com>
In reply to#32163
Rivka Miller wrote:
> 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$.

The begging of the string is zero width character. So you could use
negative lookahead (?!^).
Then the regular expression looks like:

/(?!^)\$hello\$/g

var str = '$hello$ should not be selected but',
    str1 = 'not hello but all of the $hello$ and $hello$ ... $hello$
each one ';

str.match(/(?!^)\$hello\$/g); //null
str1.match(/(?!^)\$hello\$/g); //["$hello$", "$hello$", "$hello$"]


[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web