Regex Regular Expressions – Find and Replace Text With Previous Matched Text That Regex Remembers with ( )

Using Regex to Replace Previous Matched Text

But even more useful is that you can use regex to help with replacing text as well. In the example above, you might want to keep the page numbers but replace the word “Page”. You could use then use something like:
  • Find:
    Page (d+)
  • Replace:
    This is page number 1
This will replace any occurrence of “Page” followed by a number with “This is page” followed by the same number:
  • Before:
    Page 418
  • After:
    This is page 418
The first point to note about this replacement is the use of the regex code (d+) in the Find box. The d+ code tells the search to look for numbers as above. But the use of parenthesis around the code tells the search to remember what those numbers were – to remember anything matched in the parenthesis. The other point to note is the use of the regex code 1 in the Replace box, which tells Replace to substitute the characters remembered in the Find statement for the string 1 wherever it finds it.

Using Regex to Change Formatting

As a further example of regex, this is how you might change the formatting of certain text into chapter headings.
Let’s say that you have an imported HTML file that contains lots of chapter headings, but none of them are marked using the h1 heading tag. Instead they are all marked as paragraphs like this:
<p>CHAPTER 7</p>
Assuming every paragraph like this is a chapter heading, you could use this regex:
  • Find:
  • Replace:
    <h1>Chapter 1</h1>
That’s quite a lot to digest, but if you look carefully you can see that it’s very similar to the Page number example above in that it’s remembering the digits in the chapter name and using them in the replace.
It’s the Find that is the most interesting. It breaks down like this:
  • <p> – Look for a starting paragraph tag.
  • s – Regex code to match any white space (blanks, tabs, etc.).
  • CHAPTER – Match the word CHAPTER (Regex is case-sensitive by default).
  • s – Regex code to match any white space.
  • (d+) – Regex code to match any number of digits in a row and remember them.
  • s – Regex code to match any white space.
  • </p> – Look for an end paragraph tag.
You could just use a space instead of s but s is more flexible since it will match any number of blank spaces and tabs.
So the results of that search could be:
  • Before:
    <p>  CHAPTER    14</p>
  • After:
    <h1>Chapter 14<h1>

How to enable or disable auto share Blogger post on Google plus

Google is the best, understanding the basic requirements of its users and providing best solutions. For many of us who are blogging to help, it is important to keep your community informed about your new updates and ideas. Google is constantly making changes to its online applications. In the recent changes, Google has changed Google keyword tools into Google keyword planner, Changed the interface of Google + and Gmail, introduced new featurs in Blogger.

Enable or disable auto share on Google +
Sharing post directly on Google+

One of the latest change made by Google is Auto sharing option in Blogger. If you are having a strong community over the internet which is waiting for your updates, it is good to share your thoughts to keep the conversation going. It not only bring shares and likes but it also grows your community. Good content is always appreciated and re-shared.

You may also like: Get traffic using Social media

From now onward , Google has made it easy for you to share your post on Google+. With no additional clicks , your post will be automatically shared on one of your associated Google profiles.

Automatically share posts on Google +

In Blogger, this feature is enabled by default. Whenever you will publish your next post, it will be automatically shared  on your associated Google + profile. Follow these simple steps to associate a Google profile with your blog.

1. Login to your dash board.
2. Click on Google + tab. There are three options available as explained in the image below.

Autoshare on Google + from blogger
  • Automatically share after post: This option enables or disable the auto sharing on Google+. 
  • Promote to share after posting: If you don’t want that your post is automatically published then you can check this option. This options allows you to share your blog post after it is published. A popup box will open in which you can enter little info, hash-tags etc.

  • Use Google + comments: This option enables the new Google + comment  system into your blog. This is also a new feature provided by Google.

You should read: How to embed Google+ comments in Blogger 

Disabling auto sharing on Google +

Although it is a good feature but some of you may not like this. It has its own benefits and flaws. In auto sharing environment you can not add any info or hash-tags to your post which is another seo aspect. So to disable this auto sharing option,  simply uncheck the first option i.e. “Automatically share after post“.

You may also like: Social media widget for blogger 

What next

If you are facing any problem or you have any question then you can ask me. Don’t forget to share this post with your friends.

Broken PHP Code : “Allowing Slashes in the URL Path With Apache”

I had a problem where I needed to pass an LDAP URL with two forward slashes 


in some PHP code. I couldn’t get it to work but I found out how to fix it: 

I had to configure Apache to allow encoded slashes with AllowEncodedSlashes Onin the relevant vhost by adding :

AllowEncodedSlashes On
# ...

Into the /etc/apache2/apache2.conf config file. I then ran 

sudo service apache2 restart

And the problem was fixed.

How to make user home folder after account creation

I created a new user with useradd name and forgot to use -d -m to create their home directory. I tried making one, copying the contents of /etc/skel, and chowning everything to the new user.
Aliases don’t work, such as ll, and I just have a $ at the command prompt, instead of [email protected] ~$. Also, using the scroll wheel dumps garbage on the command line 🙁
How do I fix this, or is it easier to delete the user and start over?

I just ran into this (Ubuntu 12.04) and I solved it by creating a temp user, copying over the user directory, chowning it, and finally deleting the temp user.
sudo adduser temp
sudo cp -r /home/temp /home/name
sudo chown -R name.name /home/name
sudo deluser temp 

Installing LAMP (Linux, Apache, MySQL, PHP) Web Server

Step 1: Install Apache
Apache is a free open source software which runs over 50% of the world’s web servers.

To install apache, open terminal and type in these commands:

sudo apt-get update
sudo apt-get install apache2

That’s it. To check if Apache is installed, direct your browser to your server’s IP address (eg. http://server). The page should display the words “It works!” like this.

Step 2: Install MySQL

MySQL is a powerful database management system used for organizing and retrieving data 

To install MySQL, open terminal and type in these commands:

sudo apt-get install mysql-server libapache2-mod-auth-mysql php5-mysql

During the installation, MySQL will ask you to set a root password. If you miss the chance to set the password while the program is installing, it is very easy to set the password later from within the MySQL shell.

Once you have installed MySQL, we should activate it with this command:

sudo mysql_install_db

Finish up by running the MySQL set up script:

sudo /usr/bin/mysql_secure_installation

The prompt will ask you for your current root password. 

Type it in.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Then the prompt will ask you if you want to change the root password. Go ahead and choose N and move on to the next steps. 

It’s easiest just to say Yes to all the options. At the end, MySQL will reload and implement the new changes.

By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

Remove anonymous users? [Y/n] y
... Success!

Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.

Disallow root login remotely? [Y/n] y
... Success!

By default, MySQL comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.

Remove test database and access to it? [Y/n] y
- Dropping test database...
... Success!
- Removing privileges on test database...
... Success!

Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.

Reload privilege tables now? [Y/n] y
... Success!

Cleaning up...

Once you’re done with that you can finish up by installing PHP.

Step 3: Install PHP

PHP is an open source web scripting language that is widely use to build dynamic webpages. 

To install PHP, open terminal and type in this command.

sudo apt-get install php5 libapache2-mod-php5 php5-mcrypt  php5-ldap

After you answer yes to the prompt twice, PHP will install itself.

It may also be useful to add php to the directory index, to serve the relevant php index files:

sudo nano /etc/apache2/mods-enabled/dir.conf

Add index.php to the beginning of index files. The page should now look like this:

<IfModule mod_dir.c>

DirectoryIndex index.php index.html index.cgi index.pl index.php index.xhtml index.htm


Step 4 : Test PHP
Although LAMP is installed, we can still take a look and see the components online by creating a quick php info page

To set this up, first create a new file:

sudo nano /var/www/info.php

Add in the following line:


Then Save and Exit. 

Restart apache so that all of the changes take effect:

sudo service apache2 restart

Finish up by visiting your php info page (make sure you replace the example ip address with your correct one):

It should look similar to this.

How to Fix “Arrow keys, tab-complete not working” on Unbuntu Terminal Shell

I have installed ubuntu minimal(mini.iso) on my vm. I then used recovery mode to login as root and create an account with useradd -m admin and then set a password with passwd admin.
When I login on the new account, instead of the normal prompt I only see a $ sign. If I try to tab-complete a command or file name it prints a normal tab. If I try to use the arrow keys it prints ^[[A^[[B^[[C or ^[[D. Also, ls no longer adds colors.
None of these problems were in recovery mode. How can I fix this?

That probably means that the new user account was created with /bin/sh as its login shell (which symlinks to the dash shell by default) instead of /bin/bash – you can change a user’s login shell with the ‘chsh’ command
sudo chsh -s /bin/bash <username>
(you will need to log out and back in for the change to take effect). You may also need to copy the default .bashrc from /etc/skel to get the color prompt.

In future you might want to use the ‘adduser’ command instead of ‘useradd’ – it sets up a more complete user environment including things like a default .profile and .bashrc – as well as setting the login shell to ‘bash’ 

How To Change Location Of Blockchain Data for Bitcoin-qt Client

Instructions to move blockchain directory :

Step 1. Close your Bitcoin client, if already running.
Step 2. Locate and move Bitcoin data files.
(Windows XP)
C:Documents and SettingsYourUserNameApplication dataBitcoin
(Windows Vista, Windows 7 and Windows 8)
Step 3. Copy “ Bitcoin ” directory to another drive, for example “ E: ” drive.
Step 4. Now right click on “ Properties ” of  Bitcoin.exe ” and add following in “ Target 
Step 5. Start Bitcoin, now you will see that your wallet is now loading from the new data directory.

Matrix Screensaver for Ubuntu Server Terminal

If you like playing around with your Terminal, you will love this cute little program that can create a small Matrix style animation in your Terminal.

Matrix in Your Terminal
The screenshot above can give you a better idea. The program is called cmatrix. And it is available in the Ubuntu repos by default.

sudo apt-get install cmatrix

Now, open Terminal and run “cmatrix”. Its quite cool IMO. Do take a loot at the man page also to know the small yet different configurations available with the program.