Got more questions? Find advice on: ASP | SQL | XML | Windows
Welcome to RegexAdvice Sign in | Join | Help

Breaking text into parts at keywords

  •  08-27-2008, 12:03 PM

    Breaking text into parts at keywords

    Dear colleagues,

    I like to parse a text and split it at specific keywords (e.g. k1 or k2). I'll use it in a .NET application like

    MatchCollection matches = Regex.Matches (sSrc, sRegEx); but for testing I am using RadSoftware Regex-Designer.

    My sSrc is something like:

    "k1 blakblak\r\nblakblak k2 blablabla k1 data3 k2 bla\r\nbla"

    I like to get multiple matches:

    • "k1 blakblak\r\nblakblak "
    • "k2 blablabla "
    • "k1 data3 "
    • "k2 bla\r\nbla"

    I tried: "\b(k1|k2)\b[^(k1|k2)]*", but matches ended at any character 'k' and not at the word k1 or k2, returning "k1 bla" instead of "k1 blakblak\r\nblakblak".

    I don't know how to stop matching at specific words instead instead of single characters.

    Thank you for your help.

    Regards, Thomas

     

View Complete Thread