#regex

hypolite@friendica.mrpetovan.com

Calling all #regex witches and warlocks!

I want to match individually each space at the beginning of each line of the input text. I do not want to match any other space.

Text input:

Baseline of this text
  Indentation with two spaces
    Surprise, the text has two  spaces too!

Target syntax: PCRE2 (PHP >= 7.3)
Expected matches: 6So far my best attempt is /(?<=^| ) /m but it also matches spaces beyond the first in any series of two or more consecutive spaces anywhere in the text, not just at the beginning of each line. See https://regex101.com/r/GXfJL0/1

Can you do better?

chenlevy@diasp.org

While looking for a way to have a #Bash get the main #IPv4 address of an interface I came upon this solution:

ip -f inet addr show enp1s0 | grep --color=NO -Po 'inet \K[\d.]+'

This raised the question: WT(U+2131) does \K in a (-Perl style) #regex?

It turned out to be an alternative in #Perl for a look-ahead match:

~$ echo 'hello world' | grep -oP 'hello \K(world)'
world
~$ echo 'hello world' | grep -oP 'hello (world)'
hello world
dredmorbius@joindiaspora.com

As a black programmer, I remember the cliche about problems and regular expressions in my head as "regular expressions are like calling the cops."

That's unfair to regular expressions, though, because I actually have seen them solve a problem before. Cops improving a situation? Never seen it.

https://news.ycombinator.com/item?id=7234978

pessimizer wins teh intarnets.

#cops #policebrutality #livingwhileblack #blackprogrammer #regex