You are here: PSPad forum > English discussion forum > Regular expression to replace a string only if is the begin of a line

Regular expression to replace a string only if is the begin of a line

#1 Regular expression to replace a string only if is the begin of a line

Posted by: Esgrimidor | Date: 02/07/2017 23:37 | IP: IP Logged

I need to replace in an archive with more than 80000 lines those that begins with :

12

14

2

"- "

"31 "

etc
replace with a null string

but these strings also appears at the end or the middle of some lines.

How can I propose exactly with regular expressions ?

Best Regards

--
Nice program indeed

Options: Reply | Quote | Up ^


#2 Re: Regular expression to replace a string only if is the begin of a line

Posted by: vbr | Date: 02/08/2017 00:15 | IP: IP Logged

Esgrimidor:
I need to replace in an archive with more than 80000 lines those that begins with :

12

14

2

"- "

"31 "

etc
replace with a null string

but these strings also appears at the end or the middle of some lines.

How can I propose exactly with regular expressions ?

Best Regards

Hi,
if I understand correctly, you can use a regex pattern like:

^(12|14|2|- |31 ).*

(replacing with empty string, with regular expressions checked in the replace dialog)

^ is a special character, which matches the beginning of the line (or of the whole string) in this case;
than you can list the needed line beginnings separated by the alternation symbol | and enclose the alternatives in parens;
.* matches anything that might follow after that until the line-end.

hth,
vbr

Options: Reply | Quote | Up ^


#3 Re: Regular expression to replace a string only if is the begin of a line

Posted by: Esgrimidor | Date: 02/08/2017 02:01 | IP: IP Logged

I will try now and comment.

Best Regards
smiling smiley

--
Nice program indeed

Options: Reply | Quote | Up ^


#4 Re: Regular expression to replace a string only if is the begin of a line

Posted by: Esgrimidor | Date: 02/08/2017 02:16 | IP: IP Logged

I am not doing well.

I try this in the replace window :

Search : ^(10 ).*

The string to search at the beginning of the line is "10 " .
In the replace field I put nothing as usual

But the result is no string is found.

So I am doing something wrong.

--
Nice program indeed

Options: Reply | Quote | Up ^


#5 Re: Regular expression to replace a string only if is the begin of a line

Posted by: Esgrimidor | Date: 02/08/2017 02:50 | IP: IP Logged

It's working

It's just the way you told me.
I try again and goes well !!!!

--
Nice program indeed

Options: Reply | Quote | Up ^


#6 Re: Regular expression to replace a string only if is the begin of a line

Posted by: Esgrimidor | Date: 02/08/2017 03:19 | IP: IP Logged

Something is wrong

The script deleted the entire line.

I only need to delete the characters, not the entire line.

By example

the line :
19 The objects appear too brilliant.

With
^(19 ).* must remain :

The objects appear too brilliant

I will try ^(19 ) only....

--
Nice program indeed

Options: Reply | Quote | Up ^


#7 Re: Regular expression to replace a string only if is the begin of a line

Posted by: pspad | Date: 02/08/2017 05:31 | IP: IP Logged

If you would be specific with your question, you would get correct answer on the begin
If you want to remove line numbers from the begin of lines, search for gidits on the begin:

Search: ^\d+\s+
Replace:
[x]Regular expressions

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2017 Jan Fiala
Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák