Jump to content
UBot Underground

Recommended Posts

Hey guys!

 

I am new to learning regex in python and I'm wondering how do I use regex in python to store the integers(positive and negative) i want into a list!

 

For e.g.

 

This is the data in a list.

 

[u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)', u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=5,Y=5)', u'\x1b[0m[\x1b[1m\x1b[10m\xbb\x1b[0m\x1b[36m]\x1b[0m : ']

 

How do I extract the values of A and B and store them in a variable I want using regex?

 

Thank you and appreciate it :)

Link to post
Share on other sites

Hi! I want to store the numbers in a variable be it positive or negative! I've tried this:

For example

This is the data in a list.

data =
[u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=-5,B=5)',

u'\x1b[0m[\x1b[1m\x1b[0m\xbb\x1b[0m\x1b[36m]\x1b[0m (A=5,Y=5)',

u'\x1b[0m[\x1b[1m\x1b[10m\xbb\x1b[0m\x1b[36m]\x1b[0m : ']

 

How do I extract the integer values of A and B (negative and positive) and store them in a variable so that I can work with the numbers?

I tried smth like this but the list is empty ..

for line in data[0]:
pattern = re.compile("([A-Z]=(-?\d+?),[A-Z]=(-?\d+?))")
store = pattern.findall(line)

print store

 

Thank you and appreciate it

Link to post
Share on other sites

Here you go...

 

import re

store = []
for i in data:
    vals = re.findall(r'([A-Z]=(-?\d+?),[A-Z]=(-?\d+?))', i)
    for n in vals:
        print n[1] + ',' + n[2]
        store.append(n[1] + ',' + n[2])
print store

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...