From: "Sebastjan H." Date: 2012-05-03T03:50:34+09:00 Subject: Re: array of strings - finding letter combinations Ok, thx. Just so I understand correctly, these two lines are just examples and are not part of the actual code. Since the array of strings to be searched in is actually strings in the code below. Right? Furthermore, when I used the regex as you put it, I got this error: > duplicates.rb:5: undefined (?...) sequence: /(?<=&)[a-z]/ So I changed it to /&[a-z]/ and the error was gone. Since the ampersand can also be followed by a capital letter I tried this: /&[a-z]i/ - I searched the net for modifiers, but I guess this would only work on a specific letter? So how to add the possibility of capital letter in the regex? Finally, I ran this in the terminal and I got the message that &a is taken and should a be used instead, which doesn't make any sense. I also putsed the used_chars and duplicates to check it and it's not clear to me why the puts duplicates returns: a 3. Is 3 the index? thx and kind regards, seba Jan E. wrote in post #1059230: > Sebastjan H. wrote in post #1059226: >> Hi Jan, >> >> thank you so much for this. I went through the code and I think I >> understand most of it. I am only having hard time understanding the >> beginning: >> >>> str = 'abc&exyz' >>> str[/(?<=&)[a-z]/] >> >> What do these two lines define. I guess the second one is the regex, >> what about the first one. And moreover, how are these two related? > > > The first line simply defines a test string of the format you described > in your first post (it contains the combination "&e"). The other > characters are just gibberish to show that the substring is found > inpedendent of the position or whatever. > > The regex basically says: Look for a lowercase letter from a to z, which > is preceeded by an ampersand. Using this regex in the "[]" method will > return the first matching substring (or character in this case). -- Posted via http://www.ruby-forum.com/.