正则表达式,用于在 | 之后删除所有内容(带 | ) [英] Regex for remove everything after | (with | )

查看:49
本文介绍了正则表达式,用于在 | 之后删除所有内容(带 | )的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为我的问题找到解决方案.

I was trying to find a solution for my problem.

输入:

This is the sample title | mypcworld

输出:

This is the sample title

我想在记事本++上使用简单的正则表达式删除|"之后的所有内容看起来真的很简单.但是我尝试了此处列出的其他一些正则表达式|.*$",但没有运气.问题是字符|"是等价于或的变更.所以请帮我解决它.

I want to remove everything comes after " | " using simple regex on notepad++ It seems to be really simple one. But I was tried with some other regex "|.*$" listed on here, but no luck. The problem was the character "|" was alteration equivalent of or. So please help me to solve it.

推荐答案

管道 | 是正则表达式中的特殊字符(意思是或"),你必须对它进行转义带有 \.

The pipe, |, is a special-character in regex (meaning "or") and you'll have to escape it with a \.

使用您当前的正则表达式:

Using your current regex:

\|.*$

我已经在 Notepad++ 中尝试过,正如您所提到的,它似乎运行良好.

I've tried this in Notepad++, as you've mentioned, and it appears to work well.

这篇关于正则表达式,用于在 | 之后删除所有内容(带 | )的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆