I have a list like this, stored in a .txt-file:
0 This is one Sentence
1 some more information
2 username 11
3 username 33
4 Maybe some Anime?
5 Another Anime?
6 Please no more Anime.
The list goes from 0 to 1250. What would be the best way to delete the first 1 to four digits and the space?
Any help appreciated. :)
Here's how I'd do it using a regex.
<?php
$string = '0 This is one Sentence
1 some more information
2 username 11
3 username 33
4 Maybe some Anime?
5 Another Anime?
6 Please no more Anime.';
echo preg_replace('~^\d+\s+~m', '', $string);
Output:
This is one Sentence
some more information
username 11
username 33
Maybe some Anime?
Another Anime?
Please no more Anime.
~
is a delimiter it tells the regex where the expression starts and ends. The ^
is the start of each line because of the m
modifier. The \d+
is one or more numbers. The \s+
is one or more white space characters. The +
is a quantifier meaning one or more of the preceding character, if you wanted 0 or more you would use *
.
Something like the following should work.
$filename = 'info.txt';
$contents = file($filename);
$result = ''
foreach($contents as $line) {
result .= preg_replace ('/^(\d+)[ ]+/i', '', $line)
}
Not sure how you want it to be done. If you want to do it manually then, you can achieve this using Notepad++ which is a free product.
Here is the step:
1. Open the .txt-file in Notepad++
2. Click and hold Alt key
3. Now click and drag the region you want to delete. In this case click just before zero and drag it till you reach 1250. Then without releasing the mouse drag towards the white spaces.
4. You see the region highlighted as selected.
5. Now press delete key
You are done!!
If you want to do it through a program then there are n number of ways to do it.