Tag: Regular expression

RegEx Magic – Become the Rain Man of SharePoint Programmers for 40 bucks

Regular Expressions.. the name sounds so, simple. They’re just regular expressions eh? Don’t you know?

Really, what Regular Expression are is a means to adapt stodgy, literal programming to the weird rules that humans come up with. Got a crazy inventory name that starts with 5 alphanumeric characters representing a date but ends in the Valley Girl rendition of your profit margin as matched to a syzygy? Perfect, you need a Regular Expression.

Regular expressions originated in 1956, when mathematician Stephen Cole Kleene described regular languages using his mathematical notation called regular sets.  These arose in theoretical computer science, in the subfields of automata theory (models of computation) and the description and classification of formal languages. Other early implementations of pattern matching include the SNOBOL language, which did not use regular expressions, but instead its own syntax.

A regular expression, often called a pattern, is an expression used to specify a set of strings required for a particular purpose. A simple way to specify a finite set of strings is to list its elements or members. However, there are often more concise ways to specify the desired set of strings.

Unfortunately, Regular Expressions are what make you grow bald spots and suffer chest pains. The problems they solve are so out of wack with computers ideas of what is sensible and orderly, the “regular” expressions that are needed become ridiculous endeavours in backtracking, forward looking, being optimistic, and fuzzy. What the hell..

Fortunately, in the cases where you need to be a cool developer, but not make yourself too much of a human jive-talk translator for the almighty .NET ¬†runtime, there’s the program RegEx Magic:

RegexMagic makes creating regular expressions easier than ever. While other regex tools such as RegexBuddy merely make it easier to work with regular expressions, with RegexMagic you don’t have to deal with the regular expression syntax at all. RegexMagic generates complete regular expressions to your specifications.

First, you provide RegexMagic with some samples of the text you want your regular expression to match. RegexMagic can automatically detect what sort of pattern your text looks like. Numbers, dates, and email addresses are just a few examples of the wide range of patterns that RegexMagic supports. By marking different parts of your samples, you can create regular expressions that combine multiple patterns to match exactly what you want. RegexMagic’s patterns provide many options, so you can make your regular expression as loose or as strict as you want.

Best of all, RegexMagic supports nearly all popular regular expression flavors. Select your flavor, and RegexMagic makes sure to generate a regular expression that works with it. RegexMagic can even generate snippets in many programming languages that you can copy and paste directly into your source code to implement your regular expression.

RegexMagic doesn’t automatically generate regular expressions on magic alone. But it sure makes things a lot easier by allowing you to work with your data instead of the cryptic regex syntax.

Easily Create Regexes with RegexMagic


Broken Links and Images in SharePoint Emails – A Nintex Fix Up

If you are experiencing broken images (URL’s) and links in notification emails coming from SharePoint, it may be due to a discrepency between how image and link assets are referenced in the blog posts (using only a /relative URL instead of a http://FQDN/ -based URL).

Although brittle in that it only corrects the link structure we specifically reference, the following approach does have the effect of re-basing the URL’s inside the content of the posts, so that they get their server name pre-pended and the images/links display & work as expected:


When viewing the contents of a SharePoint blog post in a notification email, for example,
images and links will be broken because their URL’s are missing the servername.

For example;
Image is trying to go to: http://blogs/Lists/Posts/Attachments/777/myimage.png
instead of https://go.mysharepoint.com/blogs/Lists/Posts/Attachments/777/myimage.png
..and so displays as a nasty red X (or nothing at all) in your users email client.

So What

So, Nintex to the rescue:
In the workflow that emails our staff notifications of the new blog post (including the blog post content), we do some string replacements on the body of the email:

1. Create a new Muliline Text variable called vOutputText
2. Create a new Regular Expression Action in your Nintex workflow:

Pattern (ignore case): src=”/blogs/Lists/
Operation: Replace Text
Replacement Text: src=”http://go.mysharepoint.com/blogs/Lists/
Store Result In: vOutputText

3. Rinse and repeat step two for each variation of links you encounter in your posts. You may find that authors consistently use other SharePoint Document Library, List and Site link patterns in their posts. You should add a new regex for each one of those.
4. Set the vOutputText to be the content of your notification email action.
5. Fire up the workflow and the email containing your blog post content should display the rebased URLs you addressed as expected.

Now What

Emails sent out now will have full URL’s in the elements you addressed and thus the links and images should work properly when the end user views the email in their client.

That being said – as mentioned this is a basic & brittle approach – chances are other link patterns will sneak in there and you’ll still get broken links when people reference new parts of your SharePont site that you didn’t account for. If you care to go deeper into Regular Expressions, the Nintex Regular Expression action is fully capable of supporting more advanced expressions that would be able to rebase URL’s that are missing their root domain name and not get tripped up on differences in subfolder paths. Since this is a Nintex Action lesson and not a Regular Expression lesson, I will refer you MSDN for learning more about Regular Expressions and to the great program RegexBuddy for developing and testing your fabulous new bullet-proof Regex’s.