0

I have this simple bit of code:

import re
kek = "./${COMPUTERNAME}/exe/jej"
reg = r"\${(COMPUTERNAME)}"
print kek
print reg
match2 = re.match(reg, kek)
print (match2)

which output:

./${COMPUTERNAME}/exe/jej

\${(COMPUTERNAME)}

None

So it doesn't match. I tested the string on regex101.com and on other websites as well, and it is working as intended (this is actually a test regex since i was trying to debug a larger regex), and i can't find why would it not work with python...

I also tried multiple combination with more or less backslashes.

Vdragon
  • 71
  • 3
  • All you need is to [use `re.search`](https://ideone.com/NS1ex4). Also, at [regex101.com](http://regex101.com), the *code generator* section is very helpful. – Wiktor Stribiżew Apr 11 '16 at 12:02
  • `re.match` ["tries to apply the pattern at the start of the string"](https://docs.python.org/2/library/re.html#re.match). – Ilja Everilä Apr 11 '16 at 12:04
  • To see the print result after you used re.search, use ´print match2.group(0)´ – Roman Apr 11 '16 at 12:04
  • I actually thought "tries to apply the pattern at the start of the string" meant it tried to only find the first match, for some reason... Thanks for correcting my stupid error. – Vdragon Apr 11 '16 at 12:10

0 Answers0