Last active
August 29, 2015 14:04
-
-
Save franzwong/c4f6f2d087b0c364ee2a to your computer and use it in GitHub Desktop.
Regular expression
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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]); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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