import java.io.Console; import java.util.regex.Pattern; import java.util.regex.Matcher; public class MyRegex{ public static void main(String[] args){ String searchTarget = "Luke Skywarker 02-123-4567 luke@daum.net"; Pattern pattern = Pattern.compile("\\d+"); Matcher matcher = pattern.matcher(searchTarget); while(matcher.find()){ System.out.println(matcher.group(0)); } } }
자바스크립트 정규표현식
var searchTarget = "Luke Skywarker 02-123-4567 luke@daum.net"; var regex = /\d+/g; console.log(searchTarget.match(regex));
C# 정규표현식
using System; using System.Text.RegularExpressions; public class RegexTest { public static void Main() { string regex = "\\d+"; string searchTarget = "Luke Skywarker 02-123-4567 luke@daum.net"; foreach (Match m in Regex.Matches(searchTarget, regex)){ Console.WriteLine(m.Value); } } }
파이썬 정규표현식
regex = r'\d+' search_target = '''Luke Skywarker 02-123-4567 luke@daum.net princess leia 010 2454 3457 leia@gmail.com''' import re result = re.findall(regex, search_target) print("\n".join(result))
댓글 없음:
댓글 쓰기