0

So i currently have this:

matches = val.match(/kickstarter\/projects(.*?)/);

To match the info after a kickstarters project url like this for example:

http://www.kickstarter.com/projects/defiant/hand-of-fate-a-card-game-that-comes-to-life?ref=home_spotlight

So with that code it gives me:

/defiant/hand-of-fate-a-card-game-that-comes-to-life?ref=home_spotlight

I want it to remove anything where there is a ? including that character itself.

4 Answers 4

3

I would actually do something like

newstr = str.split("?")[0];

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

Comments

1

You can't remove stuff by using the match function. But you surely can use

val.replace(/\?.*$/, '')

to replace anything from a question mark to the end by an empty string.

Comments

1

Just use [^?] instead of . in your re:

> url.match(/kickstarter\.com\/projects([^?]+)/)[1]
"/defiant/hand-of-fate-a-card-game-that-comes-to-life"

Comments

0

The regex you want is:

matches = val.match(/kickstarter.com\/projects([^?]*)/)

Comments

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.