MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Help: Regular expressions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg123070] Re: Help: Regular expressions
  • From: "Oleksandr Rasputinov" <oleksandr_rasputinov at hmamail.com>
  • Date: Tue, 22 Nov 2011 05:36:25 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <jad600$eig$1@smc.vnet.net>

On Mon, 21 Nov 2011 09:34:56 -0000, Shizu <slivo.vitz at msa.hinet.net> wrote:

> Hello,
>
>     Would anybody tell me what's the difference between these two --  
> with amd without "^"?
>     Regular expressions are not easy for me!
>
>
> In= StringSplit["line1\nline2\nline3", RegularExpression["(?m)^"]] //  
> InputForm
>
> Out= {"line1\n", "line2\n", "line3"}
>
> In= StringSplit["line1\nline2\nline3", RegularExpression["(?m)"]] //  
> InputForm
>
> Out= {"l", "i", "n", "e", "1", "\n", "l", "i", "n", "e", "2", "\n", "l",  
> "i",
>  "n", "e", "3"}
>
>     Thanks in advance.
>

The difference is that the latter is equivalent to

StringSplit["line1\nline2\nline3", RegularExpression[""]]

since (?m) is just an option which makes ^ match line beginnings rather  
than the beginning of the string as a whole.

If you find regular expressions opaque and difficult to work with (and who  
doesn't?) then you might be better off using Mathematica's string pattern  
syntax instead.



  • Prev by Date: How to get sub-list elements at certain position in a long list
  • Next by Date: Re: Loop problem
  • Previous by thread: Help: Regular expressions
  • Next by thread: Re: Help: Regular expressions