REGEX to trim a string after 180 characters and before |

元气小坏坏 提交于 2020-04-11 16:22:59

问题


In a pipe separated text file I need to trim the first column to no more than 180 characters.

If there is less than 180 characters I'll keep whatever is there.

Now the ugly part... I'm trying to do this in Notepad++ which means I can use find/replace with regex but not actual code. Not sure how to do a regex "If you hit a pipe before 180 you don't need to trim anything."


回答1:


You can use this regex:

^([^|]{0,180})[^|]+(.*)$

and this as the replace:

\1\2

Here's a screen shot of the Find/Replace dialog in Notepad++:

Notepad++ regex

I tested it with this dummy data:

http://pastie.org/3855302

And it resulted with this output:

http://pastie.org/3855308



来源:https://stackoverflow.com/questions/10435574/regex-to-trim-a-string-after-180-characters-and-before

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!