Earlier quoted context omitted.
Which is a fancy way to say `grep -iv '^c'`. EDIT: Oh, I missed that the input was a single line. I personally feel that control verbs are bad additions to the regexp, even though I do know that it is not a big addition to the regexp engine itself (e.g. naturally extended from posesssive quantifiers like `a++` or atomic groups `(?>foo)`). Most uses of such verbs can be expressed with combined parsers and simpler rege…
sorry, it is not same as `grep -iv '^c'` the `-o` option allows to output only matching portion, the regex is meant to extract all words other than those starting with 'c' or 'C' here's hopefully better example $ # do something with words not surround by quotes $ echo 'I like "mango" and "guava"' | perl -pe 's/"[^"]+"(*SKIP)(*F)|\w+/\U$&/g' I LIKE "mango" AND "guava"
Regular Expressions – Mastering Lookahead and Lookbehind
31–40 of 85 posts
Re: Regular Expressions – Mastering Lookahead and Lookbehind
#32Earlier quoted context omitted.
They're definitely useful, and I can cobble them together to get lots of otherwise tedious and complex parsing tasks done, but when I come back to them a week later I have no idea what the hell the pile of wingding vomit I wrote was supposed to do. I find myself writing simpler ones and tying them together with app code just for sanity's sake.
Some regex implementations allow for comments in the string; if your does not, you can probably make it work with concatenation, like: String pattern = "^https+" // match the protocol at the beginning + "([a-zA-Z])+" // match the machine name + ... Honestly, I use regular expressions because, even in such format expanded with comments, I haven't seen anything more readable after you get used to regex operators. I gue…
Re: Regular Expressions – Mastering Lookahead and Lookbehind
#33Most of the time I mention the topic of regular expressions to other developers, I usually hear self-critical commentary like "oh, I'm terrible at regex", and rarely anyone who loves them. I think they're great though, if you take the time to understand them. They're something like a Swiss Army knife for programming.
They're definitely useful, and I can cobble them together to get lots of otherwise tedious and complex parsing tasks done, but when I come back to them a week later I have no idea what the hell the pile of wingding vomit I wrote was supposed to do. I find myself writing simpler ones and tying them together with app code just for sanity's sake.
Re: Regular Expressions – Mastering Lookahead and Lookbehind
#34Earlier quoted context omitted.
A programmer saying they are terrible at regex is like a mathematician saying they are terrible at algebra.
Regex is useful when you do lots of string processing, like in webdev. Outside of that, I've found uses to be very limited - certainly not worth the upfront time investment. (I mean, sure one can cobble together something that mostly works with a regex testing tool, but you need to either take a college automata course or work through the Friedl in detail to get a basic level of proficiency).
Re: Regular Expressions – Mastering Lookahead and Lookbehind
#35You’ve got a problem you think regex can solve, now you’ve got 2 problems.
Hey, did you commit already? Still typing?
Re: Regular Expressions – Mastering Lookahead and Lookbehind
#36Most of the time I mention the topic of regular expressions to other developers, I usually hear self-critical commentary like "oh, I'm terrible at regex", and rarely anyone who loves them. I think they're great though, if you take the time to understand them. They're something like a Swiss Army knife for programming.
I think everyone who doesn't know regex should make learning regex a priority. (However, I find that lookahead and lookbehind in particular do not tend to come in handy very often. So maybe just make a mental note that this exists and then look it up when you need it.) Just learn the basics and maybe take a very quick look at the theory, finite automata (maybe the name puts people off, but its just a couple of circle…
Re: Regular Expressions – Mastering Lookahead and Lookbehind
#37Most of the time I mention the topic of regular expressions to other developers, I usually hear self-critical commentary like "oh, I'm terrible at regex", and rarely anyone who loves them. I think they're great though, if you take the time to understand them. They're something like a Swiss Army knife for programming.
Though in my experience, outside some edge cases where the format never changes (like matching a domain name in a URL) a regex is hell to maintain when you come back 3 years later.
There is also always the fun of people trying (and failing) to use regex in emails.
Re: Regular Expressions – Mastering Lookahead and Lookbehind
#38Earlier quoted context omitted.
I think everyone who doesn't know regex should make learning regex a priority. (However, I find that lookahead and lookbehind in particular do not tend to come in handy very often. So maybe just make a mental note that this exists and then look it up when you need it.) Just learn the basics and maybe take a very quick look at the theory, finite automata (maybe the name puts people off, but its just a couple of circle…
Which version of RegEx? I've "learned" RegEx two or three times and then switched language/platform and had everything I previously learned no longer work reliably. You might think I am just talking about Microsoft's quirky implementation but even in the Linux-sphere it isn't consistent see: http://www.greenend.org.uk/rjk/tech/regexp.html You take a complex format string which was design to use the fewest characters…
I'd agree with you if everything weren't so easy to look up.
Re: Regular Expressions – Mastering Lookahead and Lookbehind
#39Earlier quoted context omitted.
I think everyone who doesn't know regex should make learning regex a priority. (However, I find that lookahead and lookbehind in particular do not tend to come in handy very often. So maybe just make a mental note that this exists and then look it up when you need it.) Just learn the basics and maybe take a very quick look at the theory, finite automata (maybe the name puts people off, but its just a couple of circle…
But don't forget to point at the limitations. For example, you can't use regexps to match an arbitrary but equal number of nested opening and closing parentheses.
^(\((?1)?\))$Re: Regular Expressions – Mastering Lookahead and Lookbehind
#40Most of the time I mention the topic of regular expressions to other developers, I usually hear self-critical commentary like "oh, I'm terrible at regex", and rarely anyone who loves them. I think they're great though, if you take the time to understand them. They're something like a Swiss Army knife for programming.
The most important parts to get comfortable with are:
* Capture groups and alternation
* Character sets
* Anchors (start and end of line)
* Common escape sequences (digit, word, whitespace)
* Repeat (any, one or more, n-m)
* Common flags (global, multi-line, case-insensitive)
If you need more than that, it's time to start evaluating other tools IMO. A lookahead here and there is okay, but I'd avoid them if possible.
The best way I found to learn regex was to take a set of inputs that I wanted to match, (and a set that I didn't) and play around on https://regex101.com/ until I got a pattern that did what I wanted. You'll very quickly start to learn the above bulletpoints, and before long you'll be able to write patterns without any reference.
If you find that your regexes are getting too large or unwieldy or difficult to understand (despite knowing the above bulletpoints) then you probably need a parser or some other more suitable tool.