match first space on a line using sublime text and regular expressions

后端 未结 2 369
一整个雨季
一整个雨季 2021-02-03 23:27

So regular expressions have always been tough for me. Im getting frustrated trying to find a regular expression that will select the first white space on a line. So then i can u

相关标签:
2条回答
  • 2021-02-04 00:07

    In the spirit of @edi's answer, but with some explanation of what's happening. Match the beginning of the line with ^, then look for a sequence of characters that are not whitespace with [^\s]* or \S* (the former may work in more editors, libraries, etc than the latter), then find the first whitespace character with \s. Putting these together, you have

    ^[^\s]*\s
    

    You may want to group the non-whitespace and whitespace parts, so you can do the replacement you're talking about:

    ^([^\s]*)(\s)
    

    Then the replacement pattern is just \1/

    0 讨论(0)
  • 2021-02-04 00:20

    You can use this regex.

    ^([^\s]*)\s
    
    0 讨论(0)
提交回复
热议问题