You are here: PSPad forum > English discussion forum > Regular expression to replace a string only if is the begin of a line
Posted by: Esgrimidor | Date: 2017-02-07 22: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
Posted by: vbr | Date: 2017-02-07 23: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 stringbut 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
Posted by: Esgrimidor | Date: 2017-02-08 01:01 | IP: IP Logged
I will try now and comment.
Best Regards
--
Nice program indeed
Posted by: Esgrimidor | Date: 2017-02-08 01: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
Posted by: Esgrimidor | Date: 2017-02-08 01:50 | IP: IP Logged
It's working
It's just the way you told me.
I try again and goes well !!!!
--
Nice program indeed
Posted by: Esgrimidor | Date: 2017-02-08 02: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
Posted by: pspad | Date: 2017-02-08 04: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
Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR