pattern-matching

Why 00 is a valid integer in Python?

Why 00 is a valid integer in Python? Question: In the Python documentation : integer ::= decinteger | bininteger | octinteger | hexinteger decinteger ::= nonzerodigit (["_"] digit)* | "0"+ (["_"] "0")* bininteger ::= "0" ("b" | "B") (["_"] bindigit)+ octinteger ::= "0" ("o" | "O") (["_"] octdigit)+ hexinteger ::= "0" ("x" | "X") (["_"] …

Total answers: 1

How to match a changing pattern in python?

How to match a changing pattern in python? Question: So I have a collection of lyrics from different artists, but in the middle of all the lyrics there is always an advertisement I want to remove. It looks like this: ‘lyric lyric See John Mayer LiveGet tickets as low as $53 lyric lyric’ More generally, …

Total answers: 1

Extract with multiple Patterns

Extract with multiple Patterns Question: Having an issue that maybe some help me with. I am trying to extract two patterns from a string and place them in another column. It’s extracting the first string fine but I am missing some in getting the second one there. Here’s the string. jobseries[‘New Column’] = jobseries[‘Occupation’].str.extract(‘(GS-d+)(|)(WG-d+)’).fillna(”) The …

Total answers: 1

Regex exact match

Regex exact match Question: I have the following sentence: "The size of the lunch box is around 1.5l or 1500ml" How can I change this to: "The size of the lunch box is around 1.5 liter or 1500 milliliter" In some cases, the value might also be present as "1.5 l or 1500 ml" with …

Total answers: 2

Detect U-shave or V-shape in data series

Detect U-shave or V-shape in data series Question: I have a data series. I need to find all data segments that look look like U-shape or V-shape. Using the data below as an example, if I define the U-shape or V-shape as starting and ending point with ratio>=0.7 and all points in between are with …

Total answers: 1

How to Select Numbers from specific positions using regex?

How to Select Numbers from specific positions using regex? Question: Given the following string: {"orders":[{"id":1},{"id":2},{"id":3},{"id":4},{"id":5},{"id":6},{"id":7},{"id":8},{"id":9},{"id":10},{"id":11},{"id":648},{"id":649},{"id":650},{"id":651},{"id":652},{"id":653}],"errors":[{"code":3,"message":"[PHP Warning #2] count(): Parameter must be an array or an object that implements Countable (153)"}]} I want to select only the highlighted numbers which you can see in the image below: I tried using: [^#:](d) but it did not end …

Total answers: 2

Regex – System Requirements

Regex – System Requirements Question: I am learning regex and having difficulty when finding the pattern from the system requirements string below: "OS: Windows® 7 Processor: Intel Core i3-9100 / AMD Ryzen 3 2300X Memory: 8 GB RAM Graphics: NVIDIA® GeForce® GTX 1050 Ti / AMD Radeon™ RX 560 (4GB VRAM) Storage: 60 GB available …

Total answers: 1

How to access the matched value in the default case of structural pattern matching?

How to access the matched value in the default case of structural pattern matching? Question: With Python 3.10’s match statement, is it possible to use the value met in the default case? Or does this need to be assigned a variable before match so it can be used in the default case? match expensive_calculation(argument): case …

Total answers: 1

Is there a way to match inequalities in Python ≥ 3.10?

Is there a way to match inequalities in Python ≥ 3.10? Question: The new structural pattern matching feature in Python 3.10 is a very welcome feature. Is there a way to match inequalities using this statement? Prototype example: match a: case < 42: print(‘Less’) case == 42: print(‘The answer’) case > 42: print(‘Greater’) Asked By: …

Total answers: 3

How do I check if a string matches a set pattern in Python?

How do I check if a string matches a set pattern in Python? Question: I want to match a string to a specific pattern or set of words, like below: the apple is red is the query and the apple|orange|grape is red|orange|violet is the pattern to match. The pipes would represent words that would substitute …

Total answers: 2