AnApprentice
AnApprentice

Reputation: 110960

Extracting part of email address

Given:

[email protected]

How do I go about getting what's in between the - and the +, in this case being reply?

I'm trying:

[/\-(.*?)+/,1]

Upvotes: 1

Views: 517

Answers (2)

jjnguy
jjnguy

Reputation: 138874

The following is a general regex syntax for a pattern that should work:

^([^-]*)-([^+]*)\+.*$

Rubular says it works. Look at the match captures.

Explanation:

^        // the start of the input
([^-]*) // the 'thread' part
-        // a literal '-'
([^+]*)  // the 'reply' part
\+       // a literal '+'
.*       // the rest of the input
$        // the end

Upvotes: 2

Nakilon
Nakilon

Reputation: 35074

You need to escape +:

[/\-(.*?)\+/,1]

Upvotes: 4

Related Questions