Skip to content

Instantly share code, notes, and snippets.

@franzwong
Last active August 29, 2015 14:04
Show Gist options
  • Save franzwong/c4f6f2d087b0c364ee2a to your computer and use it in GitHub Desktop.
Save franzwong/c4f6f2d087b0c364ee2a to your computer and use it in GitHub Desktop.
Regular expression
public static void main(String[] args) {
String text = "<a href=\"http://www.google.com\">google</a>";
Pattern p = Pattern.compile("<a href=\"(.*?)\">");
Matcher m = p.matcher(text);
if (m.find()) { // use find(), don't use matches()
System.out.println(m.group(1));
}
}
var pattern = /<a href="(.*?)">/;
var text = '<a href="http://www.google.com">google</a>'
var matches = pattern.exec(text);
if (matches) {
console && console.log(matches[1]);
}
import re
def main():
text = '<a href="http://www.google.com">google</a>'
m = re.search('<a href="(.*?)">', text)
if m:
print m.group(1)
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment