0

I'm trying to split this type of string in node.js currently to send information from one server to another. I'm having trouble getting any regular expression to work considering I kind of stink at Regular Expressions in Node.js or any language at the moment. I'm trying to make it easier on myself without having a bunch of strings that replace or are split into an array. So, here's the string:

[email protected]

Is it possible to just get the name from this string without .replace() and .split()?

2
  • What do you want to extract exactly? Commented Jul 16, 2015 at 23:31
  • Basically just the name, and ignoring everything else. So it returns just name and ignores ? ! identity @ and url.url. I've tried and i've been stumped. Commented Jul 16, 2015 at 23:32

1 Answer 1

1

using matching groups:

var myString = "[email protected]";
var myRegexp = /\?(.*?)\!.+?/g;
var match = myRegexp.exec(myString);

if(match)
{
  alert(match[1]);  // name
}
else
{
  alert("no match");
}

Sign up to request clarification or add additional context in comments.

1 Comment

Well, that's what I needed thank you. I took 4 hours of trying before coming here. Thanks, credits.

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.