doulao5916 2015-06-04 20:06
浏览 102

从.txt文件列表中删除第一个字符

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. :)

  • 写回答

3条回答 默认 最新

  • douhuireng4407 2015-06-04 20:11
    关注

    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 *.

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分