Page 1 of 1

RegEx with literal '='

Posted: Sun Feb 19, 2017 2:20 am
by AgentSmithers
Hi Everyone,
In URE, Does anyone know how to escape the '=' in the regEx? I cant seem to isolate the GET var's without looking for the '=' in the middle.
Thank you!!

Code: Select all

import ure
MyString = "GET http://test.ing/test.html?Test=Value&another=one&here=two HTTP/1.1"
reg = ure.match("([A-Z]+)", MyString)
variables = ure.match("([A-z]+)[\=]([A-z]+)", MyString)
print(reg)

i=0
while 1:
	try:
		if reg is None:
			break
		else:
			print(reg.group(i))
			i+=1
	except IndexError as e:
		#print("Index Exception: {0}".format(e), type(e))
		break
	except Exception as e:
		print("Exception: {0}".format(e), type(e))
		break

print(variables)
i=0
while 1:
	try:

		if variables is None:
			break
		else:
			print(variables.group(i))
			i+=1
	except AttributeError as e:
		print("Attribute Exception: {0}".format(e), type(e))
		break
	except IndexError as e:
		#print("Index Exception: {0}".format(e), type(e))
		break
	except Exception as e:
		print("Exception: {0}".format(e), type(e))
		break

Re: RegEx with literal '='

Posted: Sun Feb 19, 2017 8:00 am
by Roberthh

Code: Select all

variables = ure.search("([A-z]+)=([A-z]+)", MyString)
will deliver at least the first assignment, test=value.
with

Code: Select all

variables.group(0) -> "Test=Value"
variables.group(1) -> "Test"
variables.group(2) -> "Value"
ure.match is anchored. It will only find patterns at the start of the string. If you want to find all occurrences of that xxx=yyyy, you have to iterate trough your source string.

Re: RegEx with literal '='

Posted: Sun Feb 19, 2017 8:33 am
by AgentSmithers
Darn, Thank you for the reply sir!