cer113
asked on
How to use Regular expression
Hi
How would i use regular expressions to change text in vi. For example I have file.txt file and I want to change word block to unblock. Please give me whole syntax since I am begginer with Regular expressions. I found some stuff on google but it is all too advanced. I dont understand people that write things for experts cause for the hell sake expert doesnt need instructions. But for begginer there is nothing on the whole internet how to learn regular expressions.
How would i replace above mentioned word in text file
:%s/\<block\>/unblock/g I tried this as advised by one guy but bash is giving me error
How would i use regular expressions to change text in vi. For example I have file.txt file and I want to change word block to unblock. Please give me whole syntax since I am begginer with Regular expressions. I found some stuff on google but it is all too advanced. I dont understand people that write things for experts cause for the hell sake expert doesnt need instructions. But for begginer there is nothing on the whole internet how to learn regular expressions.
How would i replace above mentioned word in text file
:%s/\<block\>/unblock/g I tried this as advised by one guy but bash is giving me error
:%s/block/unblock/g
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
yes this was working all good word is replaced i opened vi file.txt and in command line typed the command and word got replaced that is good
WARNING: farzani's tip works but will replace block with unblock even if it is not a whole word. For example if your file read:
To avoid this problem, try this instead
\b asserts "word boundaries" (non-word characters or start of line/end of line)
A good tour of Regular Expressions is PHP's http://www.php.net/manual/en/regexp.introduction.php actually based on Perl's Regular Expression, which is a superset of the basic regular expressions in every Unix.
What kind of block does a blockbuster bust?
you would get:What kind of unblock does a unblockbuster bust?
To avoid this problem, try this instead
:%s/\bblock\b/unblock/g
\b asserts "word boundaries" (non-word characters or start of line/end of line)
A good tour of Regular Expressions is PHP's http://www.php.net/manual/en/regexp.introduction.php actually based on Perl's Regular Expression, which is a superset of the basic regular expressions in every Unix.