As the title says, how can I achieve the following in ruby using regex or some other ruby magic?
Input
<a href="#" class="css-class">Link</a>
<img src="image.jpg" />
Desired Output
a
img
Thanks in advance
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I don’t know how regex matching is handled in ruby, but i’m pretty sure that you can retrieve groups out of the regex.
For your case the regex:
<([^\s]*).*(</.*>|/>)should do the trick.
After using it on your inputstring there will be only the tag names in group #1 for every match.