RegEx - 如何隔离特定的字符序列?

时间:2017-10-20 20:11:21

标签: regex

我需要在tab(\ t)和新行(\ n)之间隔离文本。不要删除“\ n”和“\ t”,只需抓取文本和任何其他字符,如“&”或“()”或“/”

以下是文字示例:

 u'\n\t\t\t\t\t\t\t\t\t',
 u'\n\t\t\t\t\t\t\t\t\tMilitary & Police Communication Headsets, Hearing Protectors & Accessories\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t',
 u'\n\t\t\t\t\t\t\t\t\t',
 u'\n\t\t\t\t\t\t\t\t\t',
 u'\n\t\t\t\t\t\t\t\t\tMilitary Airfield / Shelter / Water Heating Solutions\n\t\t\t\t\t\t\t\t',
 u'\n\t\t\t\t\t\t\t\t\t',
 u'\n\t\t\t\t\t\t\t\t\t',
 u'\n\t\t\t\t\t\t\t\t\tPhotonic / Optical Products & Solutions Serving the Defence & Aerospace Markets\t\t\t\t\t\t\t\t\t\n\t\t\t\t\t\t\t\t',
 u'\n\t\t\t\t\t\t\t\t\t',

尝试了许多不同的组合后,这是我能得到的最接近的组合:

[^\\n][^\\t]

我希望能得到一些帮助。

1 个答案:

答案 0 :(得分:1)

匹配TAB(\t),后跟换行符之外的任何内容([^\t]*),后跟换行符(\n):

\t[^\n]*\n

DEMO

相关问题