问题
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++:

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