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,380 other followers

Archive for the ‘RegEx’ Category

Regex – Does not contain certain Characters – Stack Overflow

Posted by jpluimers on 2018/06/01

I had to find strings containing ” of object”, but not starting with a “)”, so the regex became this:

[^)] of object

Source: [WayBackRegex – Does not contain certain Characters – Stack Overflow

–jeroen

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

Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.

Posted by jpluimers on 2018/01/18

On my list of things to try out when I need to use regular expressions again:

Test your regex by visualizing it with a live editor. JavaScript, Python, and PCRE.

Source: Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.

Via: [WayBackSergiu Toarca answering [WayBackRegex lookahead with multiple negative conditions – Stack Overflow

Note: in January 2018, Debuggex was down for a few days (Thanks Uwe for bringing that up and giving the below alternative [WayBack]).

If you are on Windows and are OK with a small cost, try this instead: [WayBack] RegexBuddy: Learn, Create, Understand, Test, Use and Save Regular Expression

–jeroen

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

Convert space indented text to markdown minus indented

Posted by jpluimers on 2018/01/17

Since I will never be good at regex, this are a few search/replace patterns I used in Atom.io to convert a plain text document space indented like this:

Version 1.23.4.15
First level indented text
Is also a first level indented text
Too a first level indented text
- First level indented text too
  Second level indented text
  Is also a second level indented text
  Too a second level indented text
  - Second level indented text too
    - A third level indented text
    Third level indented text
    Is also a third level indented text
    Too a third level indented text
98.4.32.1

to a Markdown indented one like this:

Version 1.23.4.15
- First level indented text
- Is also a first level indented text
- Too a first level indented text
- First level indented text too
 - Second level indented text
 - Is also a second level indented text
 - Too a second level indented text
 - Second level indented text too
 - A third level indented text
 - Third level indented text
 - Is also a third level indented text
 - Too a third level indented text
Version 98.4.32.1

Prepend Version when needed: https://regex101.com/r/CUhUbr/1

  • Search:
    • ^(\d+\.\d+\.\d+\.\d+)
  • Replace:
    • Version $1

Add markdown first level indentations to lines that don’t have a markdown first level indentation yet, nor start with Version nor start with a space: https://regex101.com/r/CUhUbr/2

  • Search:
    • ^(?!(Version )|(- )|( )|(\d+\.\d+\.\d+\.\d+))(.*)
  • Replace:
    • - $5

Add markdown second level indentations to lines that don’t have a markdown second level indentation yet but do have a regular second level indentation: https://regex101.com/r/CUhUbr/3

  • Search:
    • ^  (?!(- )|( ))(.*)
  • Replace:
    •   - $3

Add markdown third level indentations to lines that don’t have a markdown third level indentation yet but do have a regular third level indentation: https://regex101.com/r/CUhUbr/4

  • Search:
    • ^    (?!(- )|( ))(.*)
  • Replace:
    •     - $3

jeroen

https://regex101.com/r/CUhUbr/1

https://regex101.com/r/CUhUbr/2

https://regex101.com/r/CUhUbr/3

https://regex101.com/r/CUhUbr/4

 

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

regex – Regular expression to match DNS hostname or IP Address? – Stack Overflow

Posted by jpluimers on 2017/08/29

I’m not fond of them, but sometimes they can do their job regex – Regular expression to match DNS hostname or IP Address? – Stack Overflow

Two notes:

  1. The first answer matches either IPv4 or hostname
    (no IPv6 support yet; reminder to self: find it one day).
  2. The second answer restricts the hostname parts to be no more than 63 characters each. It doesn’t fix the total length being 255 or less
    (reminder to self: create that restriction one day).

First answer:

Read the rest of this entry »

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

JavaScript. Sigh. No real RegExp support. Sigh. Google Search results. Sigh.

Posted by jpluimers on 2017/03/01

Prologue

Every time I need to use JavaScript there’s this tiny voice in the back of my head “Please don’t”, for instance because of

JavaScript has two sets of equality operators: === and !==, and their evil twins == and !=.

Verify a URI in JavaScript with a Regular Expression using Google Search examples

This time it did it again: I used JavaScript. My need was to verify a basic URI in JavaScript, so I wrote this function based on RFC 3986 [WayBack] which in Appendix B has a nice regular expression: ^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?

function isValidUri(uri){
    var uriRegExPattern = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\?([^#]*))?(#(.*))?";
    var uriRegEx = new RegExp(uriRegExPattern); 

    return (uriRegEx.test(uri));
} 

It would crash. But JavaScript is JavaScript, so even a site like JSFiddle wouldn’t show an error (later I found out that enabling the console on http://jsbin.com/wamavacuco/edit?html,console,output does show the error in the console complete with stack trace).

Read the rest of this entry »

Posted in Development, JavaScript/ECMAScript, JSON, RegEx, Scripting, Software Development | Leave a Comment »

 
%d bloggers like this: