Pandas, Polars, PostgreSQL
Intuition\n- After solving this problem now solve Find Users With Valid E-Mails.\njs\nr\'\\bDIAB1\'  -> This pattern doesn\'t work, why?\n\nWhat \'\\b\' means? 
# Intuition\n- After solving this problem now solve [Find Users With Valid E-Mails](https://leetcode.com/problems/find-users-with-valid-e-mails/description/).\n```js\nr\'\\bDIAB1\'  -> This pattern doesn\'t work, why?\n\nWhat \'\\b\' means? Word Boundary. E.g.  \'abc DIAB100\'\n                                          |\n        Just like Any Character is Separated from its Left and Right Characters with a \'Thin Line\'. Between that \n        Space(\' \') and the character \'D\', \' D\', there is also a thin line that separated them. And this Thin_Line\n        /Position before and after an entire Word is \'Word Boundary\' i.e. \'\\b\'.\n\nA Word Character, \'\\w\' = [A-Za-z0-9_] and a Non-Word Character(\'\\W\') is anything else(+, -, * or whitespace etc)\nA Word comprised Word Characters in terms of Regex. Since Space is a Non Word Character, lets define \'\\b\' again,\n\n\'\\b\' matches the position between word characters(\'WORD\') and a non-word character(\' \', \'+\'..). So :\n```\n![image.png](https://assets.leetcode.com/users/images/783823c9-fd52-46cb-b6ed-10014f8d1fb0_1732877377.1553018.png)\n\n```js\n(2) doesnt feel right because \'+DIAB100\' is a word to us(not usa) but not to regex. It was the definition, \'\\b\' is\nthe Position between a Word and a Non-Word Character(\' \', \'+\' ..). So r\'\\bDIAB1\' will match for (2) also.\n\nTo simplify, think every Non-Word Character as a Space, \' \'. So \n\n                                    \'+DIAB100\'   =   \' DIAB100\'\n\nAnd \' DIAM100\' is True for r\'\\bDIAB1\'.\n\nNote : For any wrong information I am deeply sorry and feel free to correct me please.\n```\n```js\nSo we cant use \'\\b\' here, at least I couldnt since \'\\b\' matched even with \'+DIAB100\' according to regex.\n\n\'DIAB1\' must be at the Start of the Sentance OR at the Start of a Word(having a Whitespace before that Word)\n                    \'^DIAB1\'                 |                          \' DIAB1\'\n\n                        = r\'^DIAB1| DIAB1\' (2 DIFFERENT CONDITIONS SEPARTED BY \'|\')\n                        = r\'(^| )DIAB1\' (can also be written like this, one concise pattern)\n\n----------------------------------------------------------------------------------------------------------------\n\nr\'(^| )DIAB1\' : (By chatgpt)\n    1. Matches either the start of the string(^) OR(|) a single whitespace character(\' \') before DIAB1.\n    2. Parentheses \'()\' group the patterns together, making the \'OR\' apply only to \'^\' and \' \'.\n\nLets say \'ACNE DIAB100\' : for the first character(\'A\'), \'(^| )\' will be checked At First. If its True, then the\nregex engine will proceed to check the literal string \'DIAB1\'.\n\n---------------------------------------------------------------------------------------------------------------\n\nWait why not \'[^ ]\' instead of \'(^| )\' since \'^\' and \' \' are just Single Characters?\n`[^ ]`: Matches any character that is Not a Space. \'^\' is Meta Character, not a Literal String.\n        This is a negated character class. It looks for one character that is NOT a space immediately before DIAB1.\n```\n- In Pandas and Polars `str.contains()` used `to check if the string CONTAINS a substring that matches a pattern.` which is suitable for us because we are not evaluating our regex expression on the whole string value, from the VERY FIRST CHARACTER, e.g. to check if the string value is in a perticular pattern or not.\n# Pandas\n```js []\nimport pandas as pd\n\ndef find_patients(patients: pd.DataFrame) -> pd.DataFrame:\n    return patients.loc[ patients[\'conditions\'].str.contains(r\'(^| )DIAB1\') ]\n```\n\n# Polars\n```js []\nimport polars as pl\nfrom polars import col\n\ndef find_patients(patients: pl.LazyFrame) -> pl.LazyFrame:\n    return patients.filter( col(\'conditions\').str.contains(r"(^| )DIAB1") )\n\nfind_patients(pl.LazyFrame(patients)) .collect()\n```\n\n# PostgreSQL (Execution Order : )\n- For checking any regex expression which returns True or False, we have `~` operator in PostgreSQL. [Read this](https://www.w3resource.com/PostgreSQL/postgresql-similar-operator.php)\n```postgresql []\n-- Write your PostgreSQL query statement below\nSELECT *\nFROM patients\nWHERE conditions ~ \'(^| )DIAB1\'; -- \'(^| )DIAB1\' is Raw String like Pandas. \n```
['PostgreSQL', 'Pandas']