Thursday, July 31, 2008

Regular Expression

Regular Expression Glossary

Table 1: Anchoring Metacharacters
Metacharacter Description
^ Anchor the expression to the start of a line
$ Anchor the expression to the end of a line

Table 2: Quantifiers, or Repetition Operators
Quantifier Description
* Match 0 or more times
? Match 0 or 1 time
+ Match 1 or more times
{m} Match exactly m times
{m,} Match at least m times
{m, n} Match at least m times but no more than n times
Table 3: Predefined POSIX Character Classes
Character Class Description
[:alpha:] Alphabetic characters
[:lower:] Lowercase alphabetic characters
[:upper:] Uppercase alphabetic characters
[:digit:] Numeric digits
[:alnum:] Alphanumeric characters
[:space:] Space characters (nonprinting), such as carriage return, newline, vertical tab, and form feed
[:punct:] Punctuation characters
[:cntrl:] Control characters (nonprinting)
[:print:] Printable characters
Table 4: Alternate Matching and Grouping of Expressions
Metacharacter Description
| Alternation Separates alternates, often used with grouping operator ()
( ) Group Groups subexpression into a unit for alternations, for quantifiers, or for backreferencing (see "Backreferences" section)
[char] Character list Indicates a character list; most metacharacters inside a character list are understood as literals, with the exception of character classes, and the ^ and - metacharacters

Table 5: The REGEXP_LIKE Operator

Syntax Description
REGEXP_LIKE(source_string, pattern
[, match_parameter])
source_string supports character datatypes (CHAR, VARCHAR2, CLOB, NCHAR, NVARCHAR2, and NCLOB but not LONG). The pattern parameter is another name for the regular expression. match_parameter allows optional parameters such as handling the newline character, retaining multiline formatting, and providing control over case-sensitivity.

Table 6: The REGEXP_INSTR Function

Syntax Description
REGEXP_INSTR(source_string, pattern
[, start_position
[, occurrence
[, return_option
[, match_parameter]]]])
This function looks for a pattern and returns the first position of the pattern. Optionally, you can indicate the start_position you want to begin the search. The occurrence parameter defaults to 1 unless you indicate that you are looking for a subsequent occurrence. The default value of the return_option is 0, which returns the starting position of the pattern; a value of 1 returns the starting position of the next character following the match.

Table 7: Explanation of 5-digit + 4 Zip-Code Expression

Syntax Description
Empty space that must be matched
[:digit:] POSIX numeric digit class
] End of character list
{5} Repeat exactly five occurrences of the character list
( Start of subexpression
- A literal hyphen, because it is not a range metacharacter inside a character list
[ Start of character list
[:digit:] POSIX [:digit:] class
[ Start of character list
] End of character list
{4} Repeat exactly four occurrences of the character list
) Closing parenthesis, to end the subexpression
? The ? quantifier matches the grouped subexpression 0 or 1 time thus making the 4-digit code optional
$ Anchoring metacharacter, to indicate the end of the line

Table 8: The REGEXP_SUBSTR Function

Syntax Description
REGEXP_SUBSTR(source_string, pattern
[, position [, occurrence
[, match_parameter]]])
The REGEXP_SUBSTR function returns the substring that matches the pattern.

Table 9: The REGEXP_REPLACE Function

Syntax Description
REGEXP_REPLACE(source_string, pattern
[, replace_string [, position
[,occurrence, [match_parameter]]]])
This function replaces the matching pattern with a specified replace_string, allowing complex search-and-replace operations.

Table 10: Backreference Metacharacter

Metacharacter Description
\digit Backslash Followed by a digit between 1 and 9, the backslash matches the preceding digit-th parenthesized subexpression.
(Note: The backslash has another meaning in regular expressions; depending on the context it can also mean the Escape character

Table 11: Explanation of Pattern-Swap Regular Expression

Regular-Expression Item Description
( Start of first subexpression
. Match any single character except a newline
* Repetition operator, matches previous . metacharacter 0 to n times
) End of first subexpression; result of the match is captured in \1
(In this example, it's Ellen.)
Empty space that needs to be present
( Start of the second subexpression
. Match any single character except a newline
* Repetition operator matches the previous . metacharacter 0 to n times
) End of second subexpression; result of this match is captured in \2
(In this example, it stores Hildi.)
Empty space
( Start of third subexpression
. Match any single character except a newline
* Repetition operator matches . metacharacter 0 to n times
) End of third subexpression; result of this match is captured in \3
(In this example, it holds Smith.)

Table 12: Explanation of the Social Security Number Regular Expression

Regular-Expression Item Description
^ Start of line character (Regular expression cannot have any leading characters before the match.)
( Start subexpression and list alternates separated by the | metacharacter
[ Start of character list
[:digit:] POSIX numeric digit class
] End of character list
{3} Repeat exactly three occurrences of character list
- A hyphen
[ Start of character list
[:digit:] POSIX numeric digit class
] End of character list
{2} Repeat exactly two occurrences of character list
- Another hyphen
[ Start of character list
[:digit:] POSIX numeric digit class
] End of character list
{4} Repeat exactly four occurrences of character list
| Alternation metacharacter; ends the first choice and starts the next alternate expression
[ Start of character list
[:digit:] POSIX numeric digit class.
] End of character list
{9} Repeat exactly nine occurrences of character list
) Ending parenthesis, to close the subexpression group used for alternation
$ Anchoring metacharacter, to indicate the end of the line; no extra characters can follow the pattern


Saturday, July 26, 2008

Remember them...

My childhood heros
Bahadur

ஈரும்பு கை மாயாவி





Thanks to Lion comics/Muthu Comics
Check out this site http://thecomiclinks.blogspot.com/

Tuesday, July 22, 2008

TELNET: How to use TELNET to test SMTP address

Open Command prompt.Type
Telnet smtp_address port
telnet baby.london.com 25
220 axxx.xx-inc.com ESMTP Service (Lotus Domino Release 6.5.4FP1) ready at Tue, 22 Jul 2008 13:04:57 -0400
ehlo test.com
250-axxx.xx-inc.com Hello test.com ([10.202.10.125]), pleased to meet you
250-HELP
250-SIZE 38154240
250 PIPELINING
MAIL FROM:Admin@test.com
250 Admin@test.com... Sender OK
RCPT TO:RxxxI@Cxxxx.COM
250 Rxxx@Cxxxxxx.COM... Recipient OK
DATA
354 Enter message, end with "." on a line by itself
Subject:test message from telnet. (now hit enter twice)

test message hello mrrame (once done,type a . in the next line and press enter)
.
250 Message accepted for delivery

Now you should get an email

Monday, July 21, 2008

Oracle: Listener.ora / tnsnames.ora / Sqlnet.ora


TNSNames.ora
This file sits on client side. It provides an alias for the client to refer the database.This file will mention the protocol (TCP), Host (database server name) and the port number (default 1521)

SQLNet.ora
This file also sits on the client side. This file contains client side network configuration
parameters. You can specify
1) client domain to append to unqualified names
2) prioritize naming methods
3) Enable logging & Tracing

Listener.Ora
From 9i this file is optional. By default Oracle uses "LISTENER" to listen to the default port 1521. Usually contains
1) Listener name
2) Protocol address that it is acceptiong connection requests
3) Service its listening (SID_LIST_LISTENER).This is optional from 9i

Friday, July 18, 2008

How to capture %ERRORLEVEL% value

In Windows OS, Application's return value is stored in a system variable %ERRORLEVEL%

Sample Code //filename.cs

using System;
namespace Test
{
class TEST
{
static int Main(string[] args)
{
Console.WriteLine("Hello");
foreach(string s in args)
{ Console.WriteLine(s);
}
Console.ReadLine();
return -1;
}
}

}
Compile the above file ex: csc /t:exe filename.cs

Create a batch file with the following content
@echo off

rem testing application

@if "%ERRORLEVEL%" == "0" goto success
:fail
echo This application has failed!
echo return value = %ERRORLEVEL%
goto end
:success
echo This application has succeeded!
echo return value = %ERRORLEVEL%
goto end
:end
echo All Done.


ECHO "END"

Now run the exe and the batch file.