I need help with a Regular Expression, I need to split the text on "- "
on get the first element.
"Web Application / QA Developer (Mid-Senior Level) - BFG Interactive -
(Hilton Head Island, SC) - FullTime"
I tried this, but it doesn't work: /(.*) - /i
I don't know what code you're actually using with this regex. As already
mentioned in other email responses (one of them from me), you might want
to try using the split method with an explicit string rather than a
regex. If you want to use a substitution regex, though, you might do
something like this:
>> foo = 'I want this - not that - nor that.'
=> "I want this - not that - nor that."
>> foo.sub(/ - .*/, '')
=> "I want this"
···
On Mon, Jul 25, 2011 at 12:11:03AM +0900, Gregory Ma wrote:
> I need help with a Regular Expression, I need to split the text on "- "
> on get the first element.
Try String#split:
>> ary = "I want this - not that.".split(" - ")
=> ["I want this", "not that."]
>> ary[0]
=> "I want this"
. . . and if you want to split it into only two elements even if there
are multiple instance of the split substring, use the optional limit
argument:
>> ary = "I want this - not that - nor the other.".split(' - ', 2)
=> ["I want this", "not that - nor the other."]
>> ary[0]
=> "I want this"
>> ary[1]
=> "not that - nor the other."
···
On Mon, Jul 25, 2011 at 12:26:54AM +0900, Phillip Gawlowski wrote:
On Sun, Jul 24, 2011 at 5:11 PM, Gregory Ma <g.marcilhacy@gmail.com> wrote: