2019-05-13 19:48 阅读 90


I am writing a php class to extract data from csv file. So I need help in regular expression.

data sample

Data test
Data         867$33@!.//()7
Field somthing

Regular Expression


This should not match line 1,2 and 7 because it have only space and tab (whitespace) after Data and Field

here is my regex tester link https://regex101.com/r/xpG25l/1/

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

2条回答 默认 最新

  • 已采纳
    doushe2513 doushe2513 2019-05-13 19:52

    You can do something like


    to require an \S (non white-space character) after any amount of \h (horizontal space).

    See your updated demo

    点赞 评论 复制链接分享
  • drd2551 drd2551 2019-05-13 19:52

    You could use a negative lookahead (?!\h*$) to assert what is on the right is not 0+ times a horizontal whitespace character \h* followed by the end of the string $


    Regex demo

    If you regex should start matching from the start of the string you can append ^ to the pattern to assert the start of the string.

    Or else in the string test Field somthing there will be a match for Field somthing

    点赞 评论 复制链接分享