6

I want to replicate the following code using RegularExpression instead of StartOfLine:

In[1]:= StringSplit["line1\nline2\nline3",StartOfLine]//InputForm

Out[1]={"line1\n", "line2\n", "line3"}

Failed Attempt:

In[34]:= StringSplit["line1\nline2\nline3",RegularExpression["^/m"]]//InputForm

Out[34]= {"line1\nline2\nline3"}

How can I get this to work using Mathematica's flavor of regex?

podge cassidy
  • 483
  • 2
  • 6

1 Answers1

7

In Mathematica, you set the Regex options with prefix notation.

For multiline mode, you need to prepend your regex expression with "(?m)"

This is in the Details section of RegularExpression:

enter image description here

StringSplit["line1\nline2\nline3", RegularExpression["(?m)^"]] // InputForm
Conor
  • 7,449
  • 1
  • 22
  • 46