Regular Expression Syntax > Error 2

testing935
7 years ago

0

In python2.7
I’m programming a function that parses a site source code and it should return only the links.
Here is my code:
def LfiOneAttack(site): os.system("clear||cls") print "[*] Scan Link" request = requests.get(site) SourceCode = str(request.text.encode("utf-8")) FindLinkGroups = re.compile(r"^[(href=\"|src=\")+(?P<lien>^.\w\S.)+\"") searchResult = re.search(SourceCode, FindLinkGroups) print searchResult.groups()

and here is the error :

[*] Scan Link Traceback (most recent call last): File "requeteGene.py", line 202, in <module> __main__() File "requeteGene.py", line 103, in __main__ LFISCAN() File "requeteGene.py", line 85, in LFISCAN LfiOne(site) File "requeteGene.py", line 36, in LfiOne FindLinkGroups = re.compile(r"^[(href=\"|src=\")+(?P<lien>^.\w\S.)+\"") File "/usr/lib/python2.7/re.py", line 194, in compile return _compile(pattern, flags) File "/usr/lib/python2.7/re.py", line 251, in _compile raise error, v # invalid expression sre_constants.error: unexpected end of regular expression

Thank in advance for your answers :)

2replies
2voices
226views
dloser
7 years ago

0

The regex in general doesn’t seem to make much sense, honestly. You might want to read up a bit on it and perhaps play around with one of those online tools that shows you all the details of your expression and matches.

Also, it is very easy to debug these kind of issues, so I’m not sure why you have to ask here. Just remove parts of the expression until it works and then start adding things until it doesn’t again. Kind of makes me feel you didn’t put any effort into finding the issue yourself.

After hours of examination, I found that the ‘[**’ is unmatched.

testing935
7 years ago

0

All first thank you for your friend’s reply :)
It’s been two days since I planwhe on this error (I had other error and the one I presented to you is the last one I had)
I will test the new expression with your indication

You must be logged in to reply to this discussion. Login
1 of 3

This site only uses cookies that are essential for the functionality of this website. Cookies are not used for tracking or marketing purposes.

By using our site, you acknowledge that you have read and understand our Privacy Policy, and Terms of Service.

Dismiss