expression

create a regex that knows balanced parenthesis with maximum depth of 5

create a regex that knows balanced parenthesis with maximum depth of 5 Question: I have a problem with a regex, it is supposed to match if the depth is between 1 or 5, for example it should match with “()()()”, “((((()))))”, “(()((()))())” and not match with “())()”, “(((((())))))” och “(x)”. I have this pattern = …

Total answers: 3

Parsing / reformatting a tokenized list in python

Parsing / reformatting a tokenized list in python Question: I have lists of tokens of the form "(a OR b) AND c OR d AND c" or "(a OR b) AND c OR (d AND c)" I want to reformat these tokens into a string of the form: Expressions are of arbitrary form like (a …

Total answers: 1

Is there a C# equivalent to the Python := (an assignment expression)?

Is there a C# equivalent to the Python := (an assignment expression)? Question: Assignment expression Python 3.8 I like how it saves line. Example: for rule in rules: place = getPlace(rule) if place: print(f"Apply rule {rule.__name__} -> {place}") return place raise Exception(‘No rule found!’) ↓↓ for rule in rules: if place:= getPlace(rule): print(f"Apply rule {rule.__name__} …

Total answers: 1

Explain regular expression in Python

Explain regular expression in Python Question: Can you help me to understand this code line by line please? def word(w) pattern = re.compile(r’^[^aeiouAEIOU]+’) if re.findall(r'[^aeiouAEIOU]y[^aeiouAEIOU]’, w): pattern = re.compile(r’^[^aeiouAEIOUy]+’) beginning = re.findall(pattern, word) w = pattern.sub(”, w) w += str(beginning[0]) + ‘ay’ return w For me this part is confusing : [^aeiouAEIOU]y[^aeiouAEIOU] Thanks! Asked By: …

Total answers: 1

regex expression extract string after last comma with no numbers

regex expression extract string after last comma with no numbers Question: Given a dataframe A that looks like this: id information 001 Yellow, in town, John 002 Green, home, Lia 33 003 Yellow, garden, Peter2543 004 Red, 23 garden, 004 John891 005 Red, home, 245Sarah 006 Red 2, park 28, 67 Luke 007 Purple 03, …

Total answers: 1

Regular Expression search of a PCAP file

Regular Expression search of a PCAP file Question: We have been given a PCAP file and my job is to find: The user of the host PC tried to access some suspected website whose domain name ends with .top. Use Python (with the help of Regular Expression) to find the susceptible website. By opening the …

Total answers: 2

Starred expression in ternary operator python

Starred expression in ternary operator python Question: I wrote a python program to print the ascii value of up to every 3 numbers in a string or “ERROR” if the length is not divisible by three. I was golf the code when I ran into a SyntaxError. Code: c=input() p=len(c) c=[int(c[i:i+3])for i in range(0,len(c),3)] print(“ERROR”if …

Total answers: 3

What is the difference between an expression and a statement in Python?

What is the difference between an expression and a statement in Python? Question: In Python, what is the difference between expressions and statements? Asked By: wassimans || Source Answers: An expression is something that can be reduced to a value, for example "1+3" is an expression, but "foo = 1+3" is not. It’s easy to …

Total answers: 16