Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

split on regex using lookahead

Tags:

string

regex

I am trying to use regex to split this string

\r\r\nabc:\r\r\n\tdef ghi:\t\tS-1-5-18\r\r\n\tlll zzz:\t\tstring1\r\r\n\t

into

abc:\r\r\n\t def ghi:\t\tS-1-5-18\r\r\n\t tlll zzz:\t\tstring1\r\r\n\t

However, my current regex using lookahead only seem to be able to match this string

nabc:\r\r\n\tdef gh

regex : \w+:[\w\\n\\r \\t]+(?=[\\t]+[\w]+:)

I am using https://regex101.com to evaluate on this string.

Can i know what am i doing wrong?

Thanks

Using this in python throws up a unbalanced paranthesis exception

re.split('(?<!\\)[\w\s]+\:[\w\\\s\-]+\\t', string_to_split)
like image 988
aceminer Avatar asked Sep 20 '25 19:09

aceminer


1 Answers

(?<!\\)[\w\s]+\:[\w\\\s\-]+\\t

this one can match all of 3 string

like image 158
Shen Yudong Avatar answered Sep 22 '25 23:09

Shen Yudong