Skip to content

Category: english

Super Smash Bros is not my thing..
Instagram: http://ift.tt/1TSldrJ

Regex with negatives lookahead and lookbehind

"Looking different directions" by Paul Kline at (https://www.flickr.com/photos/paulelijah/6717953239/)
“Looking different directions” by Paul Kline.

Problem: Match strings that contains a single quotation mark ('), but not multiple ones together.

Solution:

(?<!')'(?!')

This is a regex for a single quotation mark with a (?<!') in the left and a (?!’) in the right. The (?<!') is a ?< look behind if not ! a single quotation mark '. The (?!') is a look ahead ? if not ! a single quotation mark '.

Java code:

[java]import java.util.regex.Pattern;

public class RegexProblem {
public static void main(String args[]) {
Pattern single_quote = Pattern.compile("(?<!’)'(?!’)");
String[] phrases = {
"",
"’",
"a’a",
"aaa",
"aa’aa",
"aa”aa",
"aa”’aaa",
"aaa””aaa"
};
for(String phrase: phrases){
System.out.println(String.format("For %s is %s.", phrase,
single_quote.matcher(phrase).find()));
}
}
}
[/java]

The output is:

For  is false.
For ' is true.
For a'a is true.
For aaa is false.
For aa'aa is true.
For aa''aa is false.
For aa'''aaa is false.
For aaa''''aaa is false.

From Georgetown to the National Harbor, by bike. ~12.6 miles (20.3km)..
Instagram: http://ift.tt/1GcLNSP

“If my calculations are correct, when this baby hits 88 miles per hour… you’re gonna see some serious shit.”
🚗🔥🔥🔥🕙.
Instagram: http://ift.tt/1K1708P

I’m on call this week as baked goods provider. Berry pie and apple pie.
🍰🍓🍒🍎 Instagram: http://ift.tt/1SvDmd1

“Do you realize, we’re floating in space?” The Flaming Lips #tbt Instagram: http://ift.tt/1SsQlMx

After a lot of problems with my old Galaxy S4 randomly saying “SIM card not detected” and rebooting, I tried to fix the SIM card reader. I ended up breaking it even more. I just replaced it for a new one (~US$5). I wouldn’t go as far as calling it a modular smartphone but it’s nice to own something and be able to fix it yourself.

From Instagram: http://ift.tt/1H067wA