Carl Smith
Carl Smith

Reputation: 1621

Quick Regex Help - JQuery

I am trying to use regular expressions to find part of a string from a string,

So say for example my string is:

string = "Hello my name is carl how are you doing?";

And I want to match the name "carl", how would I go about doing that?

This is what I have got,

.*?(?=\show) 

My problem is NOT matching the text "Hello my name is "

Cheers

Carl

Upvotes: 0

Views: 52

Answers (2)

Eric H.
Eric H.

Reputation: 7014

var m = myStr.match(/(\w+) how are you doing\?/)
if (m) { name = m[1]; }

Upvotes: 1

alecxe
alecxe

Reputation: 473833

Give a try to \w+(?=\show):

> var string = "Hello my name is carl how are you doing?";
> /\w+(?=\show)/.exec(string)
["carl"]

Upvotes: 2

Related Questions