Question: I am working on some project in hive and below problem is one part of it. Please note that i am going to apply the solution for this query on a subquery result /table which i have already made.

So as part of this, i am trying to print the row for each id based on column value of rnum. If rnum=2 then print both the column values, i.e., id,value. If rnum= 2 is not present for an id then then print id,'No value'.

Give below sample input and expected output.

For eg. 

for id 100, since rnum is only 1, hence print value as 'No value'

for id 200, print only value for rnum=2, i.e., xyz and ignore value for rnum=1,3 and 4

Input:

```
id      value     rnum
100      abc        1
200      def        1
200      xyz        2 
200      rtz        3
200      tgv        4

```

Expected output:

```
id                value    
100                No Value
200                xyz

```

Answer: 
Maybe, `find_all` from bs4 might work OK:

```
from bs4 import BeautifulSoup

line = '<DT><A HREF="https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html" ADD_DATE="1567455957">Clickjacking Defense · OWASP Cheat Sheet Series</A>'
soup = BeautifulSoup(line, 'html.parser')

for l in soup.find_all('a', href=True):
    print(l['href'])

```

### Output

```
https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html

```

---

If not, maybe, some expression similar to

```
(?i)href="\s*([^\s"]*?)\s*"

```

with `re.findall` might be working here: 

```
import re

expression = r'(?i)href="\s*([^\s"]*?)\s*"'

string = """
<DT><A HREF="https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html" ADD_DATE="1567455957">Clickjacking Defense · OWASP Cheat Sheet Series</A>
<DT><A HREF=" https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html " ADD_DATE="1567455957">Clickjacking Defense · OWASP Cheat Sheet Series</A>
"""

print(re.findall(expression, string))

```

### Output

```
['https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html', 'https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html']

```

---

> 
> If you wish to explore/simplify/modify the expression, it's been
>  explained on the top right panel of
>  [regex101.com](https://regex101.com/r/MyTQnz/1/). If you'd like, you
>  can also watch in [this
>  link](https://regex101.com/r/MyTQnz/1/debugger), how it would match
>  against some sample inputs.
> 
> 
> 

---
This will work:

```
import re

line = '<DT><A HREF="https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html" ADD_DATE="1567455957">Clickjacking Defense · OWASP Cheat Sheet Series</A>'

capture_regex = re.compile(r'(?<=HREF=")([^"]*)(?:")',re.IGNORECASE)
# capture_regex = re.compile(r'(?:HREF=")([^"]*)(?:")',re.IGNORECASE) this will work too
print(capture_regex.search(line).groups())
# print(capture_regex.findall(line))  # if your text contains more than one HREF

```

Out put:

```
  ['https://cheatsheetseries.owasp.org/cheatsheets/Clickjacking_Defense_Cheat_Sheet.html']

```