Re: simple regexp help needed - pull phrase out of string
- From: Patrick He <patrick.he@xxxxxxxxx>
- Date: Thu, 9 Oct 2008 22:34:27 -0500
Hello Max,
Maybe you can try this regex pattern:
irb(main):007:0> str.scan(/password:([^\s]+)/)[0]
=> ["banana"]
Regards,
Patrick
Max Williams wrote:
Hey folks. I feel like this should be easy but it's been a long week
and my brain hurts.
If i have a string like this:
string = "pending: sent at Thu Oct 09 17:25:08 +0100 2008,
password:banana errors: couldn't find user with id 230"
and i want to pull out 'banana', what's an elegant way to do it? The
password will always be followed by a space.
I can think of this:
string.match(/password:[^\s]+/)[0].gsub("password:","")
but it seems a bit clumsy and error prone. Is there a nicer way?
(Passwords can contain non alphanumeric characters btw)
.
- Follow-Ups:
- Re: simple regexp help needed - pull phrase out of string
- From: Max Williams
- Re: simple regexp help needed - pull phrase out of string
- References:
- simple regexp help needed - pull phrase out of string
- From: Max Williams
- simple regexp help needed - pull phrase out of string
- Prev by Date: Re: "print" not showing immediately in output, but "puts" is
- Next by Date: ie.start & ie.new
- Previous by thread: Re: simple regexp help needed - pull phrase out of string
- Next by thread: Re: simple regexp help needed - pull phrase out of string
- Index(es):
Relevant Pages
|