Thursday, August 04, 2011

Metacharacters and Regular Expressions

A regular expression is a pattern of text that consists of ordinary characters (for example, letters a through z) and special characters, known as metacharacters. The pattern describes one or more strings to match when searching a body of text. The regular expression serves as a template for matching a character pattern to the string being searched.

The following table contains the list of some metacharacters and their behavior in the context of regular expressions:

[Character] - [Description]

  • " \ " - Marks the next character as either a special character, a literal, a backreference, or an octal escape. For example, 'n' matches the character "n". '\n' matches a newline character. The sequence '\\' matches "\" and "\(" matches "(".
  • " ^ " - Matches the position at the beginning of the input string.
  • " $ " - Matches the position at the end of the input string.
  • " * " - Matches the preceding subexpression zero or more times.
  • " + " - Matches the preceding subexpression one or more times.
  • " ? " - Matches the preceding subexpression zero or one time.
  • " {n} " - Matches exactly n times, where n is a nonnegative integer.
  • " {n,} " - Matches at least n times, n is a nonnegative integer.
  • " {n,m} " - Matches at least n and at most m times, where m and n are nonnegative integers and n <= m.
  • " ? " - When this character immediately follows any of the other quantifiers (*, +, ?, {n}, {n,}, {n,m}), the matching pattern is non-greedy. A non-greedy pattern matches as little of the searched string as possible, whereas the default greedy pattern matches as much of the searched string as possible.
  • " . " - Matches any single character except "\n".
  • " x|y " - Matches either x or y.
  • " [xyz] " - A character set. Matches any one of the enclosed characters.
  • " [^xyz] " - A negative character set. Matches any character not enclosed.
  • " [a-z] " - A range of characters. Matches any character in the specified range.
  • " [^a-z] " - A negative range characters. Matches any character not in the specified range.
  • " \b " - Matches a word boundary, that is, the position between a word and a space.
  • " \B " - Matches a nonword boundary. 'er\B' matches the 'er' in "verb" but not the 'er' in "never".
  • " \d " - Matches a digit character.
  • " \D " - Matches a nondigit character.
  • " \f " - Matches a form-feed character.
  • " \n " - Matches a newline character.
  • " \r " - Matches a carriage return character.
  • " \s " - Matches any whitespace character including space, tab, form-feed, etc.
  • " \S " - Matches any non-whitespace character.
  • " \t " - Matches a tab character.
  • " \v " - Matches a vertical tab character.
  • " \w " - Matches any word character including underscore.
  • " \W " - Matches any nonword character.
  • " \un " - Matches n, where n is a Unicode character expressed as four hexadecimal digits. For example, \u00A9 matches the copyright symbol (©).

reference: http://www.macronimous.com/resources/writing_regular_expression_with_php.asp

Friday, September 19, 2008

LAMP (Installation)

I found this stuff very useful upon installing the very popular triad in Web Development.

First and foremost have the sourceballs to be used.

These are the links:

Here are the links and the package versions available at the time this tutorial was written


Apache
URL : http://httpd.apache.org/download.cgi
Current Version - 2.0.48


MySQL
URL : http://www.mysql.com/downloads/mysql-4.0.html
Current Version - 4.0.16


PHP
URL : http://www.php.net/downloads.php
Current Version - 4.3.4

Before installing, log in as the root user from your linux system, you can type su and press enter then enter the root password. to extract the packages downloaded

these are the commands:

$tar -zxf httpd-2.0.48.tar.gz (enter)


$tar -zxf mysql-4.0.16.tar.gz (enter)


$tar -zxf php-4.3.4.tar.gz (enter)

Compiling Apache Web Server;

Go to the apache directory through the terminal/konsole window:
this is the command:
$ ./configure --prefix=/usr/local/apache2 --enable-mods-shared=most

this will install apache to /usr/local/apach2 directory. Once the configure is done and the system returns the prompt to you, issue the following command;

$make

This will take a few minutes, once the prompt comes back again issue the following command;

$make install

Wait for a few minutes, and that's it!, Apache is installed with the exception of a few minor changes we still need to make. They are as follows..

$vi /usr/local/apache2/conf/httpd.conf


Check to make sure the following line is present in the file at the bottom of the LoadModule list, if it is not there add it;


LoadModule php4_module modules/libphp4.so


Find the DirectoryIndex line and edit it so it looks like the following;


DirectoryIndex index.html index.html.var index.php


Find the AddType application section and add the following line;


AddType application/x-httpd-php .php

Thats it, save the file and we are done with Apache. Now, on to MySQL !

Compiling MySQL -

go to the mysql directory

Follow this command by typing;


$./configure --prefix=/usr/local/mysql --localstatedir=/usr/local/mysql/data --disable-maintainer-mode --with-mysqld-user=mysql --enable-large-files-without-debug (enter)


Sit back and wait for a while while configure does its thing, once the system returns the prompt to you issue the following command;


$make (enter)


Unless you have a very fast machine this will take some time, so spend time with your family, grab a beer, go for a walk, or whatever you're into. When you get back, assuming the system has returned the prompt to you issue the following command;


$make install (enter)


Cool !, MySQL is installed, there are only a couple things left to do to get it working, first we need to create a group for MySQL as follows;


$/usr/sbin/groupadd mysql (enter)


Then we create a user called mysql which belongs to the mysql group;


$/usr/sbin/useradd -g mysql mysql (enter)


Now we install the database files as follows;


$./scripts/mysql_install_db (enter)


Then we make a couple minor ownership changes;


$ chown -R root:mysql /usr/local/mysql (enter)


$ chown -R mysql:mysql /usr/local/mysql/data (enter)


Last but not least, we use vi to add a line the ld.so.conf file as follows;


$vi /etc/ld.so.conf


And we add the following line;


/usr/local/mysql/lib/mysql


Thats it, MySQL is installed, you can run it by issuing the following command;


$/usr/local/mysql/bin/mysqld_safe --user=mysql &


And as long as we're here we might as well set a root password for MySQL as follows;


$/usr/local/mysql/bin/mysqladmin -u root password new_password


Where new_password is the password you want to use.


Ok, so far so good, on to PHP !

Compiling PHP -

Go to the PHP directory

Follow this command by typing;


#./configure --prefix=/usr/local/php --with-apxs2=/usr/local/apache2/bin/apxs --with-mysql=/usr/local/mysql (enter)


Once the prompt comes back to you issue the following command;


#make (enter)


Hang out for awhile, and then yep, you guessed it, once you have the prompt back;


#make install (enter)


Once the install finishes and you have the prompt back issue the following command;


#cp php.ini-recommended /usr/local/php/lib/php.ini (enter)


Then edit that file;


#vi /usr/local/php/lib/php.ini (enter)


And change the following;


Find the doc_root section and enter the correct path for the directory which serves your web content, such as;


doc_root= "/usr/local/apache2/htdocs/"


(this is default for apache2)


Then find the file_uploads section and change it to reflect the following;


file_uploads=Off


(for security reasons)


Thats if for PHP, now lets see if it all works..

Testing -


Assuming your MySQL process is still running from earlier, lets start Apache by issuing the following command;


$/usr/local/apache2/bin/apachectl start (enter)

This starts the Apache web server, now change into the following directory;


$cd /usr/local/apache2/htdocs (enter)

And using vi create a file called test.php;


$vi test.php


Add the following line to the file;





Save the file, then fire up your browser and point it to localhost/test.php. You should see a listing of all kinds of cool info about Apache, PHP, etc. If you do then your set !, if you don't, then take a look at your logs for Apache and MySql, and remember Google is your friend. But hopefully you do, and now you have a fully functioning setup.


Ok, one last step and we'll be done, you have everything running now, but you had to start Apache and MySql manually, that's something you don't want to have to remember to do everytime you reboot your machine, so lets fix it.


Starting Apache and MySQL Automatically -


Lets start with MySQL, as root make your working directory that of the MySQL source directory you worked with earlier, something similar to;

$cd /home/xxxx/mysql-4.0.16

Then, copy the file mysql.server to your /etc/init.d directory as follows;


$cp support-files/mysql.server /etc/init.d/mysql


Ok, lets create some links in the startup folders for run levels 3 and 5.


$cd /etc/rc3.d


$ln -s ../init.d/mysql S85mysql


$ln -s ../init.d/mysql K85mysql


$cd /etc/rc5.d


$ln -s ../init.d/mysql S85mysql


$ln -s ../init.d/mysql K85mysql


$cd ../init.d

$chmod 755 mysql


Thats it for MySQL, it should start automatically now when you reboot your machine. Now lets do the same for Apache, still as root make your working directory that of the Apache binaries as follows;


$cd /usr/local/apache2/bin


Then, copy the file called apachectl as follows;


$cp apachectl /etc/init.d/httpd


Now, for some more links;


$cd /etc/rc3.d


$ln -s ../init.d/httpd S85httpd


$ln -s ../init.d/httpd K85httpd


$cd /etc/rc5.d


$ln -s ../init.d/httpd S85httpd


$ln -s ../init.d/httpd K85httpd


And thats it for Apache !, it should start automatically along with MySQL the next time you boot your machine.


That brings us to the end of this tutorial, hopefully you found it helpful, and Good Luck !

Thursday, October 04, 2007

As a Software Developer

Software Development

It's been a year and more roaming around the (IT)Information Technology Industries. I've been a software developer for a half a year. We are using the Microsoft Access as a tool to develop a customized accounting softwares. We are making, Payroll Systems, Inventory Systems, Production Systems, Accounting Systems (Accounts Payable Systems, Accounts Receivable Systems, and etc...). It is quite effective and it is a very handy tool in doing customized accounting softwares. When you say customized, everything you want to do to a software can be done. It is quick and easy to do accounting systems softwares using the Microsoft Access products. Quite tough too, it is quite a good tool, efficient, effective but not in a long term. A good idea and a good tool is all you need in making computer based systems.

As a System programmer for a short time, it would be better to do generic modules. Generic modules, means modules that can be reused, thus, inheritance, polymorphism, and inheritance is a good technique in Software development. Object oriented programming is the trend nowadays. A nice systems flow can be a nice system too. Software Development Live Cycle strategy is really a nice prospect. Better to implement the SDLC idea in developing softwares.

Microsoft tools are really an effective tool, but an expensive one. Open source tools are also out in the market, it is your choice, using commercial tools or using open source tools. I am talking this one, this is the programmer's point of view.