The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,995 other followers

Archive for the ‘RegEx’ Category

sed double expression: match, replace in one line, overwrite file

Posted by jpluimers on 2020/04/15

A while ago, I needed to conditionally replace in files, so I used sed and a regular expression, though usually I dislike those.

However, since the system had a very basic install, there was not much choice.

Luckily back then, my Google foo returned these:

This allowed me to do a double expression (the first matches a pattern, the second performs the actual replacement within the matching lines).

In case my Google foo in the future fails:

## https://robots.thoughtbot.com/sed-102-replace-in-place
## -i causes no backup to be saved, but does in-place replacement
## since we run under git, we can always restore
## combined with a double expression (the first matches, the second executes) this is very powerful
sed -i -e '/#.*AVOID_DAILY_AUTOCOMMITS=.*$/s/^.//' /etc/etckeeper/etckeeper.conf && git diff | more

–jeroen

Posted in Development, RegEx, Software Development | Leave a Comment »

GExperts: searching for case-insensitive “T*List.Create” but not “TStringList.Create”

Posted by jpluimers on 2019/05/02

Just learned that partial exclusion can be done with the case-insensitive GExperts Grep Search like this:

T[^s][^t][^r][^i][^n][^g].*List.*\.Create

This will skip TStringList.Create, but matches TMyList.Create.

I’d rather have done something like this, but the Delphi RegEx does not support negative lookbehind:

^ *[a-zA-Z0-9_]* *: *T(<!string)[a-zA-Z0-9_]*ListO? *;$

So the alternative is to search for this:

^ *[a-zA-Z0-9_]* *: *T[a-zA-Z0-9_]*ListO? *;$

then exclude all the case insensitive TStringList entries from it, however GExperts did not support that at the time of writing.

This is an intermediate that works for some of the times:

^ *[a-zA-Z0-9_]* *: *T[^s][^t][^r][^i][^n][^g][a-zA-Z0-9_]*ListO? *;$

–jeroen

^ *[a-zA-Z0-9_]* *: *T[^s][^t][^r][^i][^n][^g][a-zA-Z0-9_]*ListO? *$;
^ *[a-zA-Z0-9_]*: .T[a-zA-Z0-9_]*ListO? *;$;
^ *[a-zA-Z0-9_]* *: *T(?!string)[a-zA-Z0-9_]*ListO? *;$

Posted in Delphi, Development, GExperts, RegEx, Software Development | Leave a Comment »

RegExr: Online Regular Expression Testing Tool

Posted by jpluimers on 2018/11/19

[WayBack] Kevlin Henney – Google+ reminded me of RegExr. Then I found out I collected the below links in 2010, but never published them. Hopefully a few still exist. Let’s see… yup: all do, but archived just in case.

Some other links (that show how much the landscape changed in 8.5 years time):

–jeroen

Posted in Development, RegEx, Software Development | Leave a Comment »

aha (Ansi HTML Adapter) with clickable URIs

Posted by jpluimers on 2018/10/02

aha is great to generate HTML from ANSI text (i.e. the coloured output on a Linux console).

But it doesn’t generate clickable URIs (it can’t yet by itself as it only looks one character in the future).

The thread at https://github.com/theZiz/aha/issues/20 suggested a case-insensitive regex through sed but the exact suggestion failed for a few reasons I will explain below.

First the bash alias (requires both aha and perl):

Read the rest of this entry »

Posted in *nix, *nix-tools, bash, bash, Development, Perl, Power User, RegEx, Scripting, Software Development | Leave a Comment »

Regular Expression Crossword Puzzle – Gregable

Posted by jpluimers on 2018/09/26

A crossword puzzle designed for geeks, every single clue is a regular expression.

Source: [WayBackRegular Expression Crossword Puzzle – Gregable

No matter your take on RegEx, I think you will be amazed just looking at it.

Related:

Via:

–jeroen

Read the rest of this entry »

Posted in Development, RegEx, Software Development | Leave a Comment »

 
%d bloggers like this: