re = /\/news\/[^?\/\n]+\/?/m
str = 'Доброго времени суток.
Подскажите, пожалуйста, как написать регулярку чтобы preg_match выдал:
0 для /news/
0 для /news/?test=1&dsds
1 для /news/название статьи/
1 для /news/название статьи
1 для /news/название статьи/?test=1&dsds
0 для всего остального
И что почитать/посмотреть про регулярки? (вики и MDN не помогают)
Спасибо!'
# Print the match result
str.scan(re) do |match|
puts match.to_s
end
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Ruby, please visit: http://ruby-doc.org/core-2.2.0/Regexp.html