Regex 正则表达式是否在行中第一次出现空格之前删除所有内容?
我想删除每行第一次出现空格之前的所有字符 初始文本样本:Regex 正则表达式是否在行中第一次出现空格之前删除所有内容?,regex,notepad++,openoffice-calc,Regex,Notepad++,Openoffice Calc,我想删除每行第一次出现空格之前的所有字符 初始文本样本: 我的狗很好 我的猫坏了 我的青蛙很坏,但它喜欢我的花园 结果必须是: 我的狗很好 我的猫坏了 我的青蛙很坏,但它喜欢我的花园 使用OpenOffice Calc或Notepad++,您将使用什么正则表达式来实现此结果? Ctrl+H 查找内容:^\S+\S+(.+)$ 替换为:$1 检查环绕 检查正则表达式 不要选中。匹配换行符 全部替换 说明: ^ : beginning of line \S+
- 我的狗很好
- 我的猫坏了
- 我的青蛙很坏,但它喜欢我的花园
- 我的狗很好
- 我的猫坏了
- 我的青蛙很坏,但它喜欢我的花园
- Ctrl+H
- 查找内容:
^\S+\S+(.+)$
- 替换为:
$1
- 检查环绕
- 检查正则表达式
- 不要选中
。匹配换行符
- 全部替换
^ : 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
$1 : content of group 1
My dog is good.
My cat is bad
My frog is bad but it loves my garden.
更换:
^ : 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
$1 : content of group 1
My dog is good.
My cat is bad
My frog is bad but it loves my garden.
给定示例的结果:
^ : 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
$1 : content of group 1
My dog is good.
My cat is bad
My frog is bad but it loves my garden.
- Ctrl+H
- 查找内容:
^\S+\S+(.+)$
- 替换为:
$1
- 检查环绕
- 检查正则表达式
- 不要选中
。匹配换行符
- 全部替换
^ : 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
$1 : content of group 1
My dog is good.
My cat is bad
My frog is bad but it loves my garden.
更换:
^ : 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
$1 : content of group 1
My dog is good.
My cat is bad
My frog is bad but it loves my garden.
给定示例的结果:
^ : 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
$1 : content of group 1
My dog is good.
My cat is bad
My frog is bad but it loves my garden.
- 按Ctrl+h打开“查找和替换”对话框
- 在“查找内容”文本框中写入
^.*?\s+(.*)$
- 在“替换为”文本框中写入
$1
- 选中正则表达式单选按钮或按ALT+g
- 您可以单击“查找下一步”按钮来验证其是否正常工作(以查找匹配项)
- 如果外观良好,请单击“全部替换”按钮或按ALT+a
:从行首开始匹配^
:匹配任意内容,任意次数,直到遇到一个空格(或多个空格)*?\s+
:捕获这些空格后面的所有内容(.*)
:匹配到行尾$
:从第行访问上面捕获的字符串$1
- 按Ctrl+h打开“查找和替换”对话框
- 在“查找内容”文本框中写入
^.*?\s+(.*)$
- 在“替换为”文本框中写入
$1
- 选中正则表达式单选按钮或按ALT+g
- 您可以单击“查找下一步”按钮来验证其是否正常工作(以查找匹配项)
- 如果外观良好,请单击“全部替换”按钮或按ALT+a
:从行首开始匹配^
:匹配任意内容,任意次数,直到遇到一个空格(或多个空格)*?\s+
:捕获这些空格后面的所有内容(.*)
:匹配到行尾$
:从第行访问上面捕获的字符串$1