/    Sign up×
Community /Pin to ProfileBookmark

Book "O’Reilly – Mastering Regular Expressions" usefulness for JavaScript?

Hi-
I had run in to some JavaScript code I wish to understand which used regular expressions, so I attempted to learn regular expressions as used in JavaScript from wed based tutorials. I found these tutorials not to my liking. They fail to dissect the regular expressions sufficiently for me to learn them. So I was quite happy when I obtained a book called “O’Reilly – Mastering Regular Expressions second edition” since when I started to read the first chapter I began to get the intense dissection of the regular expressions I had desired. However when I tried one of the expressions found in the first chapter in a JavaScript regular expression online evaluation tool it yielded a result that was not the same as what the book was saying would be the result. Perhaps I should quote the book to better explain exactly what I am talking about so from the first chapter of the book here is my quote.

[quote]

^( From|Subject|Date):
The alternation is constrained by the parentheses, so literally, this regex means
ômatch the start of the line, then one of !From”, !Subject”, or !Date”, and then match
!: “.ö Effectively, it matches:
1) start-of-line, followed by F r o m, followed by `: ‘
or 2) start-of-line, followed by S u b j e c t, followed by `
: ‘
or 3) start-of-line, followed by D a t e, followed by `: ‘
Putting it less literally, it matches lines beginning with `
From: ‘, `Subject: ‘, or
`
Date: ‘, which is quite useful for listing the messages in an email åle.

[/quote]

The online evaluation tool I was using can be found [url=http://www.projects.aphexcreations.net/rejax/]here.[/url] And supports a number of languages not just JavaScript. Switching the language switch to JavaScript and testing some test text in the text box I only got the word “From” as outlined in the quote above. Let me specify my test text. Here it is.

[quote]

orFrom: [email][email protected][/email] (The King)From:
Subject: be seein’ ya around Subject:
Ignoring Differences in Capitalization
Date: Thu, 22 Aug Date: 2002 11:04:13 Date:
Ignoring Differences in Capitalization Date:
From: The Prez [email][email protected][/email]
Ignoring Differences Subject: in Capitalization
Date: Tue, 27 Aug 2002 8:36:24
Subject: now, about your vote

[/quote]

I was however able to get this online regular expression evaluation tool to yield the exact result outlined in the book quote above. To do this it was necessary to switch the language selection switch to “Ruby” and select the global checkbox as well.

So what does this mean. Can I use my book effectively to help me learn regular expressions as used in JavaScript. Can you suggest any other sources of intense regular expression dissection the way it would be used in JavaScript. Obtaining this book took some effort which I would not want to waste. So please give me your best advice.

Sincerely
Marc

to post a comment
JavaScript

1 Comments(s)

×

Success!

Help @MarcMiller spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...