how to get html class values using regular expression in ruby

Bala

I have this below string from which I want to extract class values "ruby", "html", "java". My objective here is understanding / learning regular expressions that I have always dreaded :-).

<div class="ruby" name="ruby_doc">
<div class="html" name="html_doc">
<div class="java" name="java_doc">

This is what I have so far

str = <<END
<div class="ruby" name="ruby_doc">
<div class="html" name="html_doc">
<div class="java" name="java_doc">
END

str.scan(/"[^"]+/) #=> returns
["\"ruby", "\" name=", "\"ruby_doc", "\">\n<div class=", "\"html",...]

str.scan(/class="[^"]+/) #=> ["class=\"ruby", "class=\"html", "class=\"java"]

str.scan(/"(\w)+?"/) #=> [["ruby"], ["ruby_doc"], ["html"], ["html_doc"], ...]
sawa
str.scan(/\b(?<=class=\")[^"]+(?=\")/)
# => ["ruby", "html", "java"]

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get html tag attribute values using JavaScript Regular Expressions?

From Dev

how to get individual parameters using regular expression

From Dev

Removing a span with a specific class from HTML , but not the content using regular expression

From Dev

How to get a regular expression

From Dev

How to match values using one regular expression instead of two?

From Dev

How to match values using one regular expression instead of two?

From Dev

How to loop through a div and add a class using regular expression?

From Dev

Regular expression in ruby to get all vowels in string

From Dev

Regular expression in ruby to get all vowels in string

From Dev

How to write regular expression to get the substring from the string using regular expression in c#?

From Dev

How to get the days out of a string using Regular Expression in Python?

From Dev

How do i get the selected option Text using regular expression?

From Dev

How to get domain from a string using javascript regular expression

From Dev

How to get secondlast element from URL using regular expression

From Dev

How to get numbers by using regular expression, but only last one

From Dev

How get only characters between `(` and `)` using regular expression?

From Dev

How to get domain from a string using javascript regular expression

From Dev

How could I get the last occurrence of [0] using regular expression?

From Dev

How to get string from parenthesis using regular expression in python

From Dev

how to get specific value from a string by using regular expression

From Dev

how to get all string lines using regular expression in python

From Dev

how to get a specific value from a sentence using regular expression in php

From Dev

Regular expression to convert html class to attribute

From Dev

How to convert Ruby Regular Expression into PCRE

From Dev

How to convert this using regular expression

From Dev

Regular expression for double values using QRegExp

From Dev

Using regular expression to extract values that contain comma

From Dev

Add class property to file using regular expression

From Dev

Regular expression using shorthand character class

Related Related

  1. 1

    How to get html tag attribute values using JavaScript Regular Expressions?

  2. 2

    how to get individual parameters using regular expression

  3. 3

    Removing a span with a specific class from HTML , but not the content using regular expression

  4. 4

    How to get a regular expression

  5. 5

    How to match values using one regular expression instead of two?

  6. 6

    How to match values using one regular expression instead of two?

  7. 7

    How to loop through a div and add a class using regular expression?

  8. 8

    Regular expression in ruby to get all vowels in string

  9. 9

    Regular expression in ruby to get all vowels in string

  10. 10

    How to write regular expression to get the substring from the string using regular expression in c#?

  11. 11

    How to get the days out of a string using Regular Expression in Python?

  12. 12

    How do i get the selected option Text using regular expression?

  13. 13

    How to get domain from a string using javascript regular expression

  14. 14

    How to get secondlast element from URL using regular expression

  15. 15

    How to get numbers by using regular expression, but only last one

  16. 16

    How get only characters between `(` and `)` using regular expression?

  17. 17

    How to get domain from a string using javascript regular expression

  18. 18

    How could I get the last occurrence of [0] using regular expression?

  19. 19

    How to get string from parenthesis using regular expression in python

  20. 20

    how to get specific value from a string by using regular expression

  21. 21

    how to get all string lines using regular expression in python

  22. 22

    how to get a specific value from a sentence using regular expression in php

  23. 23

    Regular expression to convert html class to attribute

  24. 24

    How to convert Ruby Regular Expression into PCRE

  25. 25

    How to convert this using regular expression

  26. 26

    Regular expression for double values using QRegExp

  27. 27

    Using regular expression to extract values that contain comma

  28. 28

    Add class property to file using regular expression

  29. 29

    Regular expression using shorthand character class

HotTag

Archive