0

my string is like this

coder<[email protected]>

i want [email protected] back

any help will be appreciated!

4 Answers 4

3
var rcpt = 'coder<[email protected]>';
var addy = rcpt.match(/<([^>]*)>/)[1];
// addy = '[email protected]'
Sign up to request clarification or add additional context in comments.

4 Comments

Escaping < and > is not necessary: /<([^>]*)>/ or equivalently /<(.*?)>/ or even /<(.*)>/ if we assume that this is the complete string and it contains only valid email adresses.
i actually looked for a solution like say rcpt.replace(regex) okey still this yeilds result i'm happy
@Felix: ah yes, thanks. There's several regex dialects where it is necessary, and none where escaped \< or \> mess up the regex, so I routinely escape them anyway. I’ve edited the post to remove them.
@Harish: you can easily use a similar regular expression with the replace function: addy = rcpt.replace(/^.*<([^>]*)>.*$/, '$1');
2

str.split("<")[1].split(">")[0];

Comments

1

Do you know http://regexlib.com/ ?

It's a site full of regex with a regex coach to try your regex.

Also you can replace manually like this:

str.remove( string.indexOf('<'), 0 ) 
str.remove( 0, string.indexOf('>') ) 

or something equals...

1 Comment

That will yield '[email protected]', which probably isn't what the OP wants.
-1

try str.replace

<script type="text/javascript">


document.write(str.replace("coder<[email protected]>
", "[email protected]"));

</script>

1 Comment

Check the question i told like this ! not exactly this!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.