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


Groups > comp.soft-sys.math.mathematica > #6591 > unrolled thread

Help: Regular expressions

Started byShizu <slivo.vitz@msa.hinet.net>
First post2011-11-21 09:34 +0000
Last post2011-11-23 12:04 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  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

#6591 — Help: Regular expressions

FromShizu <slivo.vitz@msa.hinet.net>
Date2011-11-21 09:34 +0000
SubjectHelp: Regular expressions
Message-ID<jad600$eig$1@smc.vnet.net>
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.

[toc] | [next] | [standalone]


#6624

From"Oleksandr Rasputinov" <oleksandr_rasputinov@hmamail.com>
Date2011-11-22 10:44 +0000
Message-ID<jafue8$rs0$1@smc.vnet.net>
In reply to#6591
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.

[toc] | [prev] | [next] | [standalone]


#6649

FromJames Stein <mathgroup@stein.org>
Date2011-11-23 12:04 +0000
Message-ID<jainga$efl$1@smc.vnet.net>
In reply to#6591
<oleksandr_rasputinov@hmamail.com> wrote:

> 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.


Yes, I've been using regular expressions (infrequently ) for decades, and
usually must resort to  a reference to do what I wish. For people with
MacIntosh computers, the free text editor "TextWrangler" comes bundled with
a manual with one or two clear chapters on regular expressions.


On Tue, Nov 22, 2011 at 2:36 AM, Oleksandr Rasputinov <
oleksandr_rasputinov@hmamail.com> wrote:

> 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.
>
>

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web