last time when did you use Regular Expressions?
last time when did you use Regular Expressions?
Usually I use glob patterns for test selection.
But I did use reges yesterday to find something else. A java security file definition.
We use it for triaging test failure (running tens of thousands of tests for CPU design verification).
That use is acceptable because it is purely informational. In general you should avoid regexes at all costs. Theyāre difficult to read, and easy to get wrong. Generally they are a very big red flag.
Unfortunately they tend to get used where they shouldnāt due to lazy developers not parsing things properly.
There are some tools/libraries that act as a front-layer over regex.
They basically follow the same logic as ORMs for databases:
But thereās no common standard, and itās always language specific.
Personally I think using linters is the best option since it will highlight the footguns and recommend simpler regexes. (e.g. Swapping [0-9] for \d)
At least once every few days while coding, usually to do one of the following:
Normally I use multicursor keyboard shortcuts to select what I want and for the trickier scenarios there are also commands to go through selections one at a time so you can skip certain matches to end up with only what you want.
But sometimes there are too many false matches that you donāt want to select by hand and thatās where regex comes in handy.
For instance, finding:
⦠which can be easily done by searching for a word that doesnāt include a letter immediately before or immediately after: e.g. \Wtest\W.
Basically using the same things above
\d{4}, finding all versions: \d+\.\d+\.\d+, finding random things that a linter may have missed such as two empty lines touching each other: \n\s*\n\s*\n, etcā¦Please explain more! What happened?
Did you destroy a database? Expose credentials? Nuke the company intentionally?
Yesterday, when I had a file with a list of JSON objects, and I wanted to move the date field at the end to the beginning, so I used regex find and replace to move it. Something like \{(.*?), (ādateā: ā.*?ā) in Search, and then {$2, $1 in replace (or something close to it).
Yes, I refactor code and data using regex. I canāt be arsed to learn AWK (even though I should).
While yes, the way I had it structured looked like a CSV if you squinted a little, I do fully agree AWK canāt be used for just any old JSON.
jq is dope, but that language still feels pretty confusing IMO.
https?//[a-zA-Z0-9_-]*
I am kinda learning RE right now š
A few hours ago.
I just wanted to make a list of AD group names into a powershell array.