Bu sayfayı her yazılımcının ve uygulama geliştiricinin bilmesi gerektiğine inandığım regular expressions (düzenli ifadelere) ayırıyorum.Bu sayfada, regular expressionlarla ilgili kullandığım yardımcı araçlardan, yararı dokunabileceğini düşündüğüm bazı kodlara regular expressionlardan (regex) bahsedeceğim. |
| |
Regular Expressions kullanımı [C#] : |
// using System.Text.RegularExpressions;
// Match Örneği :
bool isMatch = Regex.IsMatch("a12sd", @"\d{2}");
// 12 match eder.
// Replace Örneği :
Regex regex = new Regex(@"\d{2}");
string sonuc = regex.Replace("a12sd", "SAYI");
// sonuc -> "aSAYIsd" |
| |
Regular Expressions kullanımı [JavaScript] : |
<html><head></head>
<script>
function isMatch(str)
{
stringToMatch = new String(str);
var result = stringToMatch.match(/\d{2}/g);
if (result == null)
{
return false;
}
return true;
}
function replaceString(str, newString)
{
stringToMatch = new String(str);
var result = stringToMatch.replace(/\d{2}/g, newString);
return result;
}
</script>
<body>
<input value="Match" type="button" onClick="alert(isMatch('a12sd'));">
<input value="Replace" type="button" onClick="alert(replaceString('a12sd', 'SAYI'));">
</body>
</html> |
| |
Yararlı olabileceğini düşündüğüm desenler : |
| ^\d{2}[\.]\d{2}[\.]\d{4}$ |
Tarih (##.##.####) |
99.99.9999 |
| (0[1-9]|[12][0-9]|3[01])[- /.](0[1-9]|1[012])[- /.](19|20)\d\d |
Tarih (##.##.####) |
12-12-1919 || 12 12 1919 || 12.12.1919 || 12/12/1919 |
| ^(([01]\d|2[0-3])(:[0-5]\d){1,2})$ |
Zaman (##:##) |
12:03 || 01:34 || 23:59 |
| ^[1-9][0-9]*.[0-9]*$ |
Decimal (##.##) |
123.0 |
| ^[\d]+$ |
Integer (##) |
123 |
|
|
Yararlı olabileceğini düşündüğüm linkler : |
Düzenli İfadeler (Regular Expressions) Nedir?
Bir Web Sitesindeki E-Mail Adreslerini Yakalamak (Düzenli İfadeler 2)
www.regular-expressions.info
www.regexlib.com
|