all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* rexexp help needed
@ 2008-12-26 14:20 henry atting
  2008-12-26 14:51 ` Lennart Borgman
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: henry atting @ 2008-12-26 14:20 UTC (permalink / raw)
  To: help-gnu-emacs

Hi,

I am trying to build a rexexp that does the following:
I have a text file where I want to replace

    Medicine:One:Two            €12.00

With 

    Medicine                    €12.00

Because I have more than one entry `Medicine' (and they 
differ slightly, something like `Medicine:Three:Four' and
so on) I have to do it with `quere-replace-regexp'.
With regexp-builder I found this:

    Medicine:.*[^€.0-9]

This works both in regexp-builder and a scratch buffer, but
unfortunately not in a file. If applied on a file replace-regexp
strips everything from the first `:'.


Kind regards
henry



^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rexexp help needed
  2008-12-26 14:20 rexexp help needed henry atting
@ 2008-12-26 14:51 ` Lennart Borgman
       [not found] ` <mailman.3376.1230303090.26697.help-gnu-emacs@gnu.org>
  2008-12-26 16:53 ` Cecilio Pardo
  2 siblings, 0 replies; 8+ messages in thread
From: Lennart Borgman @ 2008-12-26 14:51 UTC (permalink / raw)
  To: henry atting; +Cc: help-gnu-emacs

On Fri, Dec 26, 2008 at 3:20 PM, henry atting
<nspm_01@literaturlatenight.de> wrote:
> Hi,
>
> I am trying to build a rexexp that does the following:
> I have a text file where I want to replace
>
>    Medicine:One:Two            €12.00
>
> With
>
>    Medicine                    €12.00
>
> Because I have more than one entry `Medicine' (and they
> differ slightly, something like `Medicine:Three:Four' and
> so on) I have to do it with `quere-replace-regexp'.
> With regexp-builder I found this:
>
>    Medicine:.*[^€.0-9]
>
> This works both in regexp-builder and a scratch buffer, but
> unfortunately not in a file. If applied on a file replace-regexp
> strips everything from the first `:'.

You have to escape the [] with \. That is a bit tricky since you have
to double the escape character. (One for text escaping, one for regexp
char escaping.)

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rexexp help needed
       [not found] ` <mailman.3376.1230303090.26697.help-gnu-emacs@gnu.org>
@ 2008-12-26 16:17   ` henry atting
  2008-12-26 17:11     ` Lennart Borgman
       [not found]     ` <mailman.3380.1230311518.26697.help-gnu-emacs@gnu.org>
       [not found]   ` <mailman.3378.1230308108.26697.help-gnu-emacs@gnu.org>
  1 sibling, 2 replies; 8+ messages in thread
From: henry atting @ 2008-12-26 16:17 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: henry atting, help-gnu-emacs

Zitat - Lennart Borgman * Fr Dez 26 2008 um 15:51 -

> On Fri, Dec 26, 2008 at 3:20 PM, henry atting
> <nspm_01@literaturlatenight.de> wrote:
>> Hi,
>>
>> I am trying to build a rexexp that does the following:
>> I have a text file where I want to replace
>>
>>    Medicine:One:Two            €12.00
>>
>> With
>>
>>    Medicine                    €12.00
>>
>> Because I have more than one entry `Medicine' (and they
>> differ slightly, something like `Medicine:Three:Four' and
>> so on) I have to do it with `quere-replace-regexp'.
>> With regexp-builder I found this:
>>
>>    Medicine:.*[^€.0-9]
>>
>> This works both in regexp-builder and a scratch buffer, but
>> unfortunately not in a file. If applied on a file replace-regexp
>> strips everything from the first `:'.
>
> You have to escape the [] with \. That is a bit tricky since you have
> to double the escape character. (One for text escaping, one for regexp
> char escaping.)


Mmh, IIRC I tried it already with escape sequences. Anyway, if I do so I
get:

    Replaced 0 occurences

No difference if I try it in a scratch buffer or a file.
Without escaping it works in a scratch buffer at least. ;)






^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rexexp help needed
  2008-12-26 14:20 rexexp help needed henry atting
  2008-12-26 14:51 ` Lennart Borgman
       [not found] ` <mailman.3376.1230303090.26697.help-gnu-emacs@gnu.org>
@ 2008-12-26 16:53 ` Cecilio Pardo
  2 siblings, 0 replies; 8+ messages in thread
From: Cecilio Pardo @ 2008-12-26 16:53 UTC (permalink / raw)
  To: henry atting; +Cc: help-gnu-emacs

henry atting <nspm_01@literaturlatenight.de> writes:

> Hi,
>
> I am trying to build a rexexp that does the following:
> I have a text file where I want to replace
>
>     Medicine:One:Two            €12.00
>
> With 
>
>     Medicine                    €12.00
>
> Because I have more than one entry `Medicine' (and they 
> differ slightly, something like `Medicine:Three:Four' and
> so on) I have to do it with `quere-replace-regexp'.
> With regexp-builder I found this:
>
>     Medicine:.*[^€.0-9]
>
> This works both in regexp-builder and a scratch buffer, but
> unfortunately not in a file. If applied on a file replace-regexp
> strips everything from the first `:'.
>
>
> Kind regards
> henry
>

I think that regexp should be

Medicine:[^€.0-9]*

if you want to match the whole line except the price.




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rexexp help needed
       [not found]   ` <mailman.3378.1230308108.26697.help-gnu-emacs@gnu.org>
@ 2008-12-26 16:54     ` harven
  0 siblings, 0 replies; 8+ messages in thread
From: harven @ 2008-12-26 16:54 UTC (permalink / raw)
  To: help-gnu-emacs

henry atting <nspm_01@literaturlatenight.de> writes:

> Zitat - Lennart Borgman * Fr Dez 26 2008 um 15:51 -
>
>> On Fri, Dec 26, 2008 at 3:20 PM, henry atting
>> <nspm_01@literaturlatenight.de> wrote:
>>> Hi,
>>>
>>> I am trying to build a rexexp that does the following:
>>> I have a text file where I want to replace
>>>
>>>    Medicine:One:Two            €12.00
>>>
>>> With
>>>
>>>    Medicine                    €12.00
>>>
>>> Because I have more than one entry `Medicine' (and they
>>> differ slightly, something like `Medicine:Three:Four' and
>>> so on) I have to do it with `quere-replace-regexp'.
>>> With regexp-builder I found this:
>>>
>>>    Medicine:.*[^€.0-9]
>>>
>>> This works both in regexp-builder and a scratch buffer, but
>>> unfortunately not in a file. If applied on a file replace-regexp
>>> strips everything from the first `:'.

[^€.0-9] matches newline. So it probably takes everything until end of line.
Put a newline in the bracket (input C-q C-j , appears as ^J below).
Also beware of trailing whitespaces. The following works for me, 
with M-x replace-regexp (no query)

Replace regexp:
\(Medicine\)\(.*\)\([^€.0-9^J]\)
With:
 \1\,(make-string (length \2) 32)\3

There may be simpler ways to do it (btw 32 is the character code for space)


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rexexp help needed
  2008-12-26 16:17   ` henry atting
@ 2008-12-26 17:11     ` Lennart Borgman
  2008-12-26 23:04       ` Thierry Volpiatto
       [not found]     ` <mailman.3380.1230311518.26697.help-gnu-emacs@gnu.org>
  1 sibling, 1 reply; 8+ messages in thread
From: Lennart Borgman @ 2008-12-26 17:11 UTC (permalink / raw)
  To: henry atting; +Cc: help-gnu-emacs

On Fri, Dec 26, 2008 at 5:17 PM, henry atting
<nspm_01@literaturlatenight.de> wrote:
> Zitat - Lennart Borgman * Fr Dez 26 2008 um 15:51 -
>
>> On Fri, Dec 26, 2008 at 3:20 PM, henry atting
>> <nspm_01@literaturlatenight.de> wrote:
>>> Hi,
>>>
>>> I am trying to build a rexexp that does the following:
>>> I have a text file where I want to replace
>>>
>>>    Medicine:One:Two            €12.00
>>>
>>> With
>>>
>>>    Medicine                    €12.00
>>>
>>> Because I have more than one entry `Medicine' (and they
>>> differ slightly, something like `Medicine:Three:Four' and
>>> so on) I have to do it with `quere-replace-regexp'.
>>> With regexp-builder I found this:
>>>
>>>    Medicine:.*[^€.0-9]
>>>
>>> This works both in regexp-builder and a scratch buffer, but
>>> unfortunately not in a file. If applied on a file replace-regexp
>>> strips everything from the first `:'.
>>
>> You have to escape the [] with \. That is a bit tricky since you have
>> to double the escape character. (One for text escaping, one for regexp
>> char escaping.)
>
>
> Mmh, IIRC I tried it already with escape sequences. Anyway, if I do so I
> get:
>
>    Replaced 0 occurences
>
> No difference if I try it in a scratch buffer or a file.
> Without escaping it works in a scratch buffer at least. ;)

Eh, sorry. Everything (nearly) I wrote before was wrong. You do not
need to escape []. Something like this is what you want

  (re-search-forward "Medicine:[^€]*")

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rexexp help needed
       [not found]     ` <mailman.3380.1230311518.26697.help-gnu-emacs@gnu.org>
@ 2008-12-26 17:46       ` henry atting
  0 siblings, 0 replies; 8+ messages in thread
From: henry atting @ 2008-12-26 17:46 UTC (permalink / raw)
  To: Lennart Borgman; +Cc: henry atting, help-gnu-emacs

Zitat - Lennart Borgman * Fr Dez 26 2008 um 18:11 -

> On Fri, Dec 26, 2008 at 5:17 PM, henry atting
> <nspm_01@literaturlatenight.de> wrote:
>> Zitat - Lennart Borgman * Fr Dez 26 2008 um 15:51 -
>>
>>> On Fri, Dec 26, 2008 at 3:20 PM, henry atting
>>> <nspm_01@literaturlatenight.de> wrote:
>>>> Hi,
>>>>
>>>> I am trying to build a rexexp that does the following:
>>>> I have a text file where I want to replace
>>>>
>>>>    Medicine:One:Two            €12.00
>>>>
>>>> With
>>>>
>>>>    Medicine                    €12.00
>>>>
>>>> Because I have more than one entry `Medicine' (and they
>>>> differ slightly, something like `Medicine:Three:Four' and
>>>> so on) I have to do it with `quere-replace-regexp'.
>>>> With regexp-builder I found this:
>>>>
>>>>    Medicine:.*[^€.0-9]
>>>>
>>>> This works both in regexp-builder and a scratch buffer, but
>>>> unfortunately not in a file. If applied on a file replace-regexp
>>>> strips everything from the first `:'.
>>>
>>> You have to escape the [] with \. That is a bit tricky since you have
>>> to double the escape character. (One for text escaping, one for regexp
>>> char escaping.)
>>
>>
>> Mmh, IIRC I tried it already with escape sequences. Anyway, if I do so I
>> get:
>>
>>    Replaced 0 occurences
>>
>> No difference if I try it in a scratch buffer or a file.
>> Without escaping it works in a scratch buffer at least. ;)
>
> Eh, sorry. Everything (nearly) I wrote before was wrong. You do not
> need to escape []. Something like this is what you want
>
>   (re-search-forward "Medicine:[^€]*")

Yes, thanks, with `*' at the end it works fine.


henry




^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: rexexp help needed
  2008-12-26 17:11     ` Lennart Borgman
@ 2008-12-26 23:04       ` Thierry Volpiatto
  0 siblings, 0 replies; 8+ messages in thread
From: Thierry Volpiatto @ 2008-12-26 23:04 UTC (permalink / raw)
  To: help-gnu-emacs

"Lennart Borgman" <lennart.borgman@gmail.com> writes:

> On Fri, Dec 26, 2008 at 5:17 PM, henry atting
> <nspm_01@literaturlatenight.de> wrote:
>> Zitat - Lennart Borgman * Fr Dez 26 2008 um 15:51 -
>>
>>> On Fri, Dec 26, 2008 at 3:20 PM, henry atting
>>> <nspm_01@literaturlatenight.de> wrote:
>>>> Hi,
>>>>
>>>> I am trying to build a rexexp that does the following:
>>>> I have a text file where I want to replace
>>>>
>>>>    Medicine:One:Two            €12.00
>>>>
>>>> With
>>>>
>>>>    Medicine                    €12.00
>>>>
>>>> Because I have more than one entry `Medicine' (and they
>>>> differ slightly, something like `Medicine:Three:Four' and
>>>> so on) I have to do it with `quere-replace-regexp'.
>>>> With regexp-builder I found this:
>>>>
>>>>    Medicine:.*[^€.0-9]
>>>>
>>>> This works both in regexp-builder and a scratch buffer, but
>>>> unfortunately not in a file. If applied on a file replace-regexp
>>>> strips everything from the first `:'.
>>>
>>> You have to escape the [] with \. That is a bit tricky since you have
>>> to double the escape character. (One for text escaping, one for regexp
>>> char escaping.)
>>
>>
>> Mmh, IIRC I tried it already with escape sequences. Anyway, if I do so I
>> get:
>>
>>    Replaced 0 occurences
>>
>> No difference if I try it in a scratch buffer or a file.
>> Without escaping it works in a scratch buffer at least. ;)
>
> Eh, sorry. Everything (nearly) I wrote before was wrong. You do not
> need to escape []. Something like this is what you want
>
>   (re-search-forward "Medicine:[^€]*")

Hi,
with query-replace-regexp:

M-x: :[a-zA-Z]*:[A-Za-z]* RET RET


-- 
A + Thierry Volpiatto
Location: Saint-Cyr-Sur-Mer - France





^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2008-12-26 23:04 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-12-26 14:20 rexexp help needed henry atting
2008-12-26 14:51 ` Lennart Borgman
     [not found] ` <mailman.3376.1230303090.26697.help-gnu-emacs@gnu.org>
2008-12-26 16:17   ` henry atting
2008-12-26 17:11     ` Lennart Borgman
2008-12-26 23:04       ` Thierry Volpiatto
     [not found]     ` <mailman.3380.1230311518.26697.help-gnu-emacs@gnu.org>
2008-12-26 17:46       ` henry atting
     [not found]   ` <mailman.3378.1230308108.26697.help-gnu-emacs@gnu.org>
2008-12-26 16:54     ` harven
2008-12-26 16:53 ` Cecilio Pardo

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.