Skip to content

Instantly share code, notes, and snippets.

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
import re
input = "Johny johny yes pappa! Eating sugar?"
regex = "(J|j)ohny"
pattern = re.compile(regex)
for item in pattern.finditer(input):
print 'Match ', item.group(),' found at ',item.start() ,', ',item.end()
@arunkumaranand
arunkumaranand / regex_sample.java
Last active August 29, 2015 14:16
Regular expression Java Sample
// Java Regex sample
String input = "Johny johny yes pappa! Eating sugar?";
String regex = "(J|j)ohny";
Pattern pattern = Pattern.compile(regex); // Compile the pattern
Matcher matcher = pattern.matcher(input); // Generate the matcher for the input and pattern
while(matcher.find()) { // Find match
String matchedContent = matcher.group(); // get the matched content
int start = matcher.start();
int end = matcher.end();
@arunkumaranand
arunkumaranand / closure_py_example.py
Last active August 29, 2015 14:14
Closure example using Python
__author__ = 'Arunkumar Anand'
def startAt(x):
def incrementBy(y):
return x + y
return incrementBy
closure1 = startAt(1)
closure2 = startAt(5)