Regular Exp usage in different Programming Laguages
Posted by admin on March 8th, 2010 filed in PythonRegular Expression is an expression for identifying patterns, it is very easy and very powerful for data processing. Almost every language and most advanced editors are giving Regular Expression support. Even we can write Regular Expression in Database queries, all most all database engines are supporting regular expressions in database queries. we can see these regular expressions in Dos scripts also.
Regular Expressions in Dos:
1. open dos and type cd \
2. cd docu*, press Enter
3. In findstr(dos command ) /R attribute is to use Regular expression mode
Regular Expressions in c++:
RegEx Engine is implemented through RegExpr Class.
Code:
RegExpr re;
re.compile("a*(cb|c*)d");
Regular Expressions in Visual C++:
The Visual C++ also implements the RegEx Engine with RegEx class.
Code:
#include <regex>
basic_regex<char> regex("[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,4}"
,basic_regex<char>::icase);
cout<< std::boolalpha
<< regex_match("GoOD@DOMAIN.COM", regex)<< std::endl;
Regular Expressions in Java:
Java uses java.util.regex Package for pattern matching, even we can use regular expressions on
String class for splitting and matching desired data. For more examples we can visit
sun web site RegEx doc
code:
Pattern pattern = Pattern.compile(console.readLine("%nEnter your regex: "));
Matcher matcher = pattern.matcher(console.readLine("Enter input string to search: "));
matcher.find()
Even all scripting languages are providing RegEx Engine for on fly Data processing.
Regular Expressions in JavaScript:
We can execute regular expressions in JavaScript with RegExp.exec function,
Here RegExp means an expression
Code:
/s(amp)le/i.exec("Sample text")
Regular Expressions in Python:
Python provides RegEx Engine with re package.
Code:
import re
p = re.compile('[a-z]+')
m = p.match( 'tempo')
Even for more information Python re.
Regular Expressions Usage in DataBase Queries:
We can embed Regular Expressions in the Database Sql queries, like this
Query:
SELECT description FROM testTable WHERE REGEXP_LIKE(description,'[mn]');
click Here for more support
RegEx usage minimizes lot of work for Data processing but we should be very careful at usage,
we should minimize the usage of RegEx other wise it may effect on Project maintainance we should
write a comment for every part of the expression other wise in the future it takes more and more
time for modifications in the RegularExpression
The below links are helpful for checking Regular Expressions in on-line.
http://www.gskinner.com/RegExr/ - Best site for Checking Reg Ex

May 12th, 2010 at 4:16 am
Об этом не может быть и речи….
Россию; оплату Regular Expression is an expression for identifying patterns, it is very easy and very powerful for data processing…..