Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/ruby
- input = "[Brett](http://brettterpstra.com/) can't replicate [the](!g) issue."
- input.gsub!(/\[(.*?)\]\((\!.+?)\)/) do |match|
- link_text = $1
- link_info = $2
- puts "link_text:"
- puts link_text
- puts "link_info:"
- puts link_info
- puts "\n"
- end
- input = "[Brett](http://brettterpstra.com/) can't replicate [the](!g) issue."
- # Remove the `\!` from the regex
- input.gsub!(/\[(.*?)\]\((.+?)\)/) do |match|
- link_text = $1
- link_info = $2
- # Only match links starting with `!`
- if link_info[0,1] == '!'
- puts "This was a SearchLink link:"
- puts link_text
- puts link_info
- puts "\n"
- else
- puts "This was not a SearchLink link:"
- puts link_text
- puts link_info
- puts "\n"
- end
- end
- # Output:
- # link_text:
- # Brett](http://brettterpstra.com/) can't replicate [the
- # link_info:
- # !g
- #
- # This was not a SearchLink link:
- # Brett
- # http://brettterpstra.com/
- #
- # This was a SearchLink link:
- # the
- # !g
- #
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement