I have several strings of data, which are all very similar, however I
only wish to look at some strings which match a specific criteria and
ignore the rest. Some samples are below - I want the first and the last
string and to ignore the middle string.
I have constructed a regex to say capture any string starting with
/software/ and ending with /Microsoft/Windows NT/CurrentVersion, but
with only one string within slashes in the middle, see below:
re = /\/software\/([^\/]*)\/Microsoft\/Windows NT\/CurrentVersion$/
2.0.0p195 :018 > strings.each do |s|
2.0.0p195 :019 > m = re.match(s)
2.0.0p195 :020?> puts m.captures if m
2.0.0p195 :021?> end
$$$PROTO.HIV
CMI-CreateHive{199ADFC2-6E16-4946-BE90-5A3EC3A60902}
[^\/] is a character class that will match everything that is not a
forward slash. This is repeated zero or more times.
Jesus.
···
On Wed, Dec 4, 2013 at 5:36 PM, Stuart Clarke <lists@ruby-forum.com> wrote:
Hi all,
I have several strings of data, which are all very similar, however I
only wish to look at some strings which match a specific criteria and
ignore the rest. Some samples are below - I want the first and the last
string and to ignore the middle string.
I have constructed a regex to say capture any string starting with
/software/ and ending with /Microsoft/Windows NT/CurrentVersion, but
with only one string within slashes in the middle, see below:
On Dec 4, 2013, at 11:50 AM, Jesús Gabriel y Galán <jgabrielygalan@gmail.com> wrote:
On Wed, Dec 4, 2013 at 5:36 PM, Stuart Clarke <lists@ruby-forum.com> wrote:
Hi all,
I have several strings of data, which are all very similar, however I
only wish to look at some strings which match a specific criteria and
ignore the rest. Some samples are below - I want the first and the last
string and to ignore the middle string.
I have constructed a regex to say capture any string starting with
/software/ and ending with /Microsoft/Windows NT/CurrentVersion, but
with only one string within slashes in the middle, see below:
re = /\/software\/([^\/]*)\/Microsoft\/Windows NT\/CurrentVersion$/
2.0.0p195 :018 > strings.each do |s|
2.0.0p195 :019 > m = re.match(s)
2.0.0p195 :020?> puts m.captures if m
2.0.0p195 :021?> end
$$$PROTO.HIV
CMI-CreateHive{199ADFC2-6E16-4946-BE90-5A3EC3A60902}
[^\/] is a character class that will match everything that is not a
forward slash. This is repeated zero or more times.