Forum Discussion
Python script is not working with Regex contains "|" or "*"
Hi Anonymous ,
I'm not good at Python script, are you sure your python script correct?
By my test with the script below in Query Editor, there is no any error. So I 'm afraid that Python script is working with Regex contains "|" or "*" .
From the blog, we could know how to use "|" and "*" in Python script.
# 'dataset' holds the input data for this script
import re
pattern = '^a|b..cd*n$'
test_string = 'abycdn'
result = re.match(pattern, test_string)
if result:
print("Search successful.")
else:
print("Search unsuccessful.")
Please check your script again, if that is completely correct and you still have problem in Power BI , please let me know.
Best Regards,
Cherry
Hi v-piga-msft Cherry,
Thanks for looking into my issue. The Python script is correct, if I use is for a simple regex pattern. Like the below one.
# 'dataset' holds the input data for this script
regex = r'(\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})'
dataset['Timestamp'] = dataset['description'].str.extract(regex)
So, it is only not working when the regex become complex somehow. Does POWER BI offers any native filter option based on the regex, then the Python script is not really necessary.
- brightcitrus6 years agoFrequent Visitor
Hi Anonymous v-piga-msft,
I am having the same issue using a Python script with regular expressions in Power BI. Did you find a solution to run the script? Please let me know. You can also reply to my post here. Thank you!