Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: string extraction #411

Open
bsteephenson opened this issue Mar 5, 2015 · 3 comments
Open

Feature: string extraction #411

bsteephenson opened this issue Mar 5, 2015 · 3 comments

Comments

@bsteephenson
Copy link
Contributor

I think this could be a useful feature.

_.extract('My name is {0} and I like {1}', 'My name is Ben and I like pie')
=> ['Ben', 'pie']

myFun = _.extract('My name is {0} and I like {1}')
myFun('My name is Ben and I like pie')
=> ['Ben', 'pie']
@stoeffel
Copy link
Collaborator

stoeffel commented May 2, 2015

Sounds interesting. Do you want to make a PR?

@esamattis
Copy link
Owner

Feels like limited version of regexp.

This is not too bad imo:

'My name is Ben and I like pie'.match(/My name is ([^ ]+) and I like ([^ ]+)/).slice(1)
# => ["Ben", "pie"]

@Belema
Copy link

Belema commented Dec 7, 2015

@bsteephenson, @stoeffel, I have just opened a pull request for this: #466.

@epeli, the implementation is more complex in order to handle ordering, cases where the template string already contains regex patterns, and other edge cases...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants