Hi i want regular expression to find one or more than one substrings inside big string match some criteria like.
"I have done my best to document all the [switches] and characters that I can locate.Regular expressions [allow] you to group like [parts] of the substring into"
the result should be like these substrings
switches,allow,parts
and in this case
"I have done my best to document all the [switches] and character.
result should be the only “switches”
Thanks in advance.
You need String#scan:
The Regexp will match any chars between ‘[‘ and ‘]’. The pattern .+? means NOT do this thing greedy. When a “]” is matched, this part is over. Otherwise, if we use [.*] , the matching will return [switches……parts].