The Wiert Corner – irregular stream of stuff

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

  • My work

  • My badges

  • Twitter Updates

  • My Flickr Stream




    More Photos
  • Pages

  • All categories

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

    Join 1,724 other followers

Archive for the ‘RegEx’ Category

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

Posted by jpluimers on 2017/03/01


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,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 »

grep: searching for pipes, optional characters

Posted by jpluimers on 2016/09/22

For my own reference as RegEx is a write-only language:

Search for pipes means just back-slash escaping them:

grep "\|S\|" products.txt > s-rated-products.txt

Search for optional charactes (in this case searching for both the singular and plural form of a word) can be done by grouping the optional part in parentheses:

grep -i "Movie(s)?" products.txt > movie-products.txt

Search for either OR:

grep -E "foo|bar" products.txt > foo-or-bar-products.txt
egrep "foo|bar" products.txt > foo-or-bar-products.txt

Note that the Borland grep does not support the OR syntax, but egrep does.



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

findstr as alternative for recursive grep search

Posted by jpluimers on 2016/04/27

Usually I use the old Borland grep.exe that still ships with Delphi. Too bad it is 16-bit app which does not recognise Unicode.

FindStr does. Though much slower and with limited regular expression capabilities, can do recursive searches too:

findstr /spin /c:"string to find" *.*

The /spin is a shortcut for these case insensitive command-line options (the full list of possible options is below):

  /S         Searches for matching files in the current directory and all
  /I         Specifies that the search is not to be case-sensitive.
  /N         Prints the line number before each line that matches.
  /P         Skip files with non-printable characters.

Sometimes I leave out the /P to include binary files.



Read the rest of this entry »

Posted in Batch-Files, Development, Power User, RegEx, Scripting, Software Development, Windows, Windows 7, Windows 8, Windows 8.1, Windows NT, Windows Server 2000, Windows Server 2003, Windows Server 2003 R2, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Vista, Windows XP | Leave a Comment »

.NET Regex Tester – Regex Storm

Posted by jpluimers on 2016/01/26

Greate stuff:

Online .NET regular expression tester with real-time highlighting and detailed results output.

Allowed me to quickly verify the pattern PWWWC\d\dFE\d\d_\d\d\d\d-\d\d-\d\d\.zip matches only one of these filenames:


Source: .NET Regex Tester – Regex Storm

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

7 Linux Grep OR, Grep AND, Grep NOT Operator Examples

Posted by jpluimers on 2015/10/31

Question: Can you explain how to use OR, AND and NOT operators in Unix grep command with some examples?

Source: 7 Linux Grep OR, Grep AND, Grep NOT Operator Examples

Posted in *nix, *nix-tools, Power User, RegEx | Leave a Comment »

%d bloggers like this: