Regex to fetch an entry with same start match and different end match

Viewed 45

I have a text which will have multiple record information. All the records will begin with same regex pattern and each record will have some unique text. Here I want to fetch only the entry name and value of the record which contains the text "Entertainment Extra 4K". I tried to with a regex and but as the regex begn match to first one I'm always getting the first record values.

https://regex101.com/r/MAAc1s/1

In the above link, I'm want to get only the below record info,

<input type='radio' class="radio" id="bb_radio128411" name='484' value='13'
-----
----Entertainment Extra 4K

Any suggestions would be really appreciated

1 Answers

Use

name='(\d+)'\s+value='(\d+)'[^<>]*Entertainment Extra 4K

See proof.

EXPLANATION

--------------------------------------------------------------------------------
  name='                   'name=\''
--------------------------------------------------------------------------------
  (                        group and capture to \1:
--------------------------------------------------------------------------------
    \d+                      digits (0-9) (1 or more times (matching
                             the most amount possible))
--------------------------------------------------------------------------------
  )                        end of \1
--------------------------------------------------------------------------------
  '                        '\''
--------------------------------------------------------------------------------
  \s+                      whitespace (\n, \r, \t, \f, and " ") (1 or
                           more times (matching the most amount
                           possible))
--------------------------------------------------------------------------------
  value='                  'value=\''
--------------------------------------------------------------------------------
  (                        group and capture to \2:
--------------------------------------------------------------------------------
    \d+                      digits (0-9) (1 or more times (matching
                             the most amount possible))
--------------------------------------------------------------------------------
  )                        end of \2
--------------------------------------------------------------------------------
  '                        '\''
--------------------------------------------------------------------------------
  [^<>]*                   any character except: '<', '>' (0 or more
                           times (matching the most amount possible))
--------------------------------------------------------------------------------
  Entertainment Extra      'Entertainment Extra 4K'
  4K
Related