Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6624

Re: Help: Regular expressions

From "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject Re: Help: Regular expressions
Date 2011-11-22 10:44 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jafue8$rs0$1@smc.vnet.net> (permalink)
References <jad600$eig$1@smc.vnet.net>

Show all headers | View raw


On Mon, 21 Nov 2011 09:34:56 -0000, Shizu <slivo.vitz@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.

Back to comp.soft-sys.math.mathematica | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Help: Regular expressions Shizu <slivo.vitz@msa.hinet.net> - 2011-11-21 09:34 +0000
  Re: Help: Regular expressions "Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com> - 2011-11-22 10:44 +0000
  Re: Help: Regular expressions James Stein <mathgroup@stein.org> - 2011-11-23 12:04 +0000

csiph-web