正则表达式删除行中第一个空格出现之前的所有内容?

mar*_*rya 1 regex notepad++ openoffice-calc

I would like to remove all the characters before the first space occurrence for each line.

Sample of initial text:

  • 2:2 My dog is good.
  • 1:234 My cat is bad
  • 14:2 My frog is bad but it loves my garden.

Result must be:

  • My dog is good.
  • My cat is bad
  • My frog is bad but it loves my garden

What regular expression would you use to achieve this result using OpenOffice Calc or Notepad++?

Tot*_*oto 5

  • Ctrl+H
  • 找什么: ^\S+\s+(.+)$
  • 用。。。来代替: $1
  • 检查环绕
  • 检查正则表达式
  • 请勿检查 . matches newline
  • Replace all

说明:

^           : beginning of line
  \S+       : 1 or more non space character
  \s+       : 1 or more space character
  (.+)      : group 1, 1 or more any character (ie. rest of the line)
$           : end of line
Run Code Online (Sandbox Code Playgroud)

替代:

$1      : content of group 1
Run Code Online (Sandbox Code Playgroud)

给定示例的结果:

My dog is good.
My cat is bad
My frog is bad but it loves my garden.
Run Code Online (Sandbox Code Playgroud)


Kam*_*yan 5

  • Ctrl+h打开查找和替换对话框
  • ^.*?\s+(.*)$在“查找内容”文本框中写入
  • $1在“替换为”文本框中写入
  • 检查Regular Expression单选按钮或按ALT+g
  • 您可以单击Find Next按钮以验证其是否正常工作(以查找匹配项)
  • Replace All如果看起来不错,请单击按钮或按ALT+a

解释:

  • ^ : 从行首匹配
  • .*?\s+: 匹配任意次数,直到遇到一个空格(或更多空格)
  • (.*):捕获这些空格后的所有内容
  • $: 匹配到行尾
  • $1: 从 line 访问上面捕获的字符串