regular expression problem

Eric Bouyoux eric.bouyoux at insidefr.com
Thu Apr 22 14:04:22 CEST 2010


Hi,

It works fine too.

Eric.

Le 22/04/2010 13:41, Matthijs van Aalten a écrit :
> How about this one:
> replace_in_selection("^(.*[^,]),?$", "input\t\\1,", "regex")
>
> This searches for:
> Beginning of line (and start memorizing)
> zero or more characters,
> followed by one character which may _not_ be a comma, (and stop memorizing)
> optionally a comma,
> followed by end of line.
>
> Regards,
> Matthijs
>
>
>
> -----Original Message-----
> From: discuss-bounces at nedit.org [mailto:discuss-bounces at nedit.org] On Behalf Of Eric Bouyoux
> Sent: Thursday 22 April 2010 13:28
> To: General NEdit discussion list
> Subject: Re: regular expression problem
>
> Hi,
>
> Thank you for your answer. What I do is the following, which seems to be
> more or less the same as your last example :
> replace_in_selection("^(.+),*$", "input\t\\1,", "regex")
>
> The idea is : I take what is in (), I add "input\t" before and "," after.
> But it seems to be a greedy expression which goes to the end of line and
> does not stop to the first ",".
>
> Regards.
>
> Eric.
>
> Le 22/04/2010 10:24, Eddy De Greef a écrit :
>   
>> I guess that you used something like
>>    replace_all("toto|toto,", "input toto,", "regex")
>> in which case the first match takes precedence.
>>
>> You could reverse the order:
>>    replace_all("toto,|toto", "input toto,", "regex")
>> or better yet, use something like
>>    replace_all("toto,?", "input toto,", "regex")
>> where the comma is quantified (quantified matching is greedy by
>> default). That should give you the desired behaviour.
>>
>> Eddy
>>
>> On 04/22/2010 09:43 AM, Eric Bouyoux wrote:
>>     
>>> Hi,
>>>
>>> I have created a small macro to help me to modify some Verilog files to
>>> replace a line that contains some characters followed or not by a comma
>>> by the same line starting with 'input' and ending by a comma.
>>> Ex :
>>> the line contains :
>>> toto
>>> or the line contains :
>>> toto,
>>>
>>> In both case, I want to replace it by :
>>> input toto,
>>>
>>> The result I get is :
>>> if the line does not contain any comma, then it works.
>>> If the line already contains a comma, the resulting line contains 2
>>> commas.
>>>
>>> Could you help me ?
>>>
>>> Regards.
>>>
>>> Eric.
>>>       
>   



More information about the Discuss mailing list