Tags » Regex

Regular Expressions in Java

Introduction

You might remember that one article I wrote about Lambda expressions in Java last year. In that article I took a quick look at what Lambda expressions are and how you can use them in Java. 1,650 more words

English

Regular Expressions

I just found a site that attempts to create regular expressions based on sample input. It then does predictive analysis to spit out a guess as to what kind of regular expression you’re trying to build, to save you the time to build it. 9 more words

App Development

extract e-mails from a file

Problem
You have a text file and you want to extract all the e-mail addresses from it. For research purposes, of course.

Solution

#!/usr/bin/env python3

import re
import sys

def extract_emails_from(fname):
    with open(fname, errors='replace') as f:
        for line in f:
            match = re.findall(r'[\w\.-]+@[\w\.-]+', line)
            for e in match:
                if '?' not in e:
                    print(e)
                    
def main():
    fname = sys.argv[1]
    extract_emails_from(fname)

##############################################################################

if __name__ == "__main__":
    if len(sys.argv) == 1:
        print("Error: provide a text file!", file=sys.stderr)
        exit(1)
    # else
    main()
… 54 more words
Python

Regex prime checker

This Java snippet uses a regular expression for something way different than they were designed for: a primality check.

public static boolean prime(int n) {
    return !new String(new char[n]).matches(".?|(..+?)\\1+");
} 551 more words
Explanation

Resources for Learning Regular Expressions (RegEx / RegExp)

Regular Expressions (better known as RegEx) is still something of a mystery for me because I don’t use it often enough to commit it memory.  Every time I find a situation where using a RegEx would be ideal, I have to start from scratch and find some useful resources to help me overcome forgetfulness or learn some new syntaxes to accomplish the goal. 134 more words

Tutorial

To Optimize or Not To Optimize

TL;DR

Oft times, coding is trying to find a balance between multiple parameters. Some good factors we measure code upon are –

Tech

... and the winner is?

Every now and then I see an application and I think… this one is going to be a game changer for Studio users.  There have been a few, but the top two for me have been the “ 1,445 more words

CAT Tools