extract string using ruby regex

rubyist

I have a string as

"The Fashion Project - The Project of Fashion-Technology and Science-institute"

I need to extract the strings as project name and its description so that it returns an array . So the output should be

array[0] = "The Fashion Project"
array[1] = "The Project of Fashion-Technology and Science-institute"

I tried it with split method but the array[1] returned "The Project of Fashion" I tried it as

"The Fashion Project - The Project of Fashion-Technology and Science-institute".split('-')
anusha

You can try this also

2.1.2 :007 > s = "The Fashion Project - The Project of Fashion-Technology and Science-institute"
 => "The Fashion Project - The Project of Fashion-Technology and Science-institute" 
2.1.2 :008 > s.split(/\s[-\b]\s/)
 => ["The Fashion Project", "The Project of Fashion-Technology and Science-institute"] 
2.1.2 :009 >

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

regular expression to extract a string with ruby regex

From Dev

Extract string if found using regex

From Dev

extract number in string using regex

From Java

Regex to extract paragraph from a text using ruby

From Dev

Extract USD amout at beginning of string using regex

From Dev

Using regex to extract numbers and symbols from string

From Dev

Need a regex to extract a portion of the string using java

From Dev

Using regex to extract information from string

From Dev

Extract a string from textfile using JS regex

From Dev

Extract ip address from a string using regex

From Dev

Python - Extract pattern from string using RegEx

From Dev

extract numbers within a string using regex

From Dev

Using regex to extract first half of string

From Dev

Extract a word from string using regex

From Dev

Extract values from a string using regex

From Dev

Using regex pattern to extract required string?

From Dev

Extract phone numbers from string using regex?

From Dev

How to extract numbers from a string using regex?

From Dev

Extract string from URL using Regex

From Dev

Extract specific chars from a string using a regex

From Dev

Extract word from string Using python regex

From Dev

extract url from string using regex

From Dev

Extract string and assign to the variable using regex in Python

From Dev

How to extract substring from a string using regex?

From Dev

Extract values from string using regex groups

From Dev

java: extract string from input using regex

From Dev

Using regex to extract an image url from string

From Dev

Using regex to extract data from the following string

From Dev

How to extract the unmatched portion of a string using a regex

Related Related

HotTag

Archive