Shell

http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameter-Expansion

t='main.exe' ; echo ${t/.exe/}
#| main
echo ${EMAIL/@/(a)}
echo ${PWD// /_} 
echo ${OSTYPE}
# linux-gnu
echo ${OSTYPE/-/_}
# linux_gnu
echo ${OSTYPE%-gnu}
echo ${OSTYPE%-*}
# linux

parameter substitutions ${-=?+}

echo ${OS:=unix}

@tag: bash sh

GNU make

${SRCS:.cpp=.o}

grep / sed

echo " match \"what\" is \"inside quotes\" only " | grep -o '"[^\"]*"'
echo " match \"what\" is \"inside quotes\" only " | sed 's/"[^\"]*"/\n&\n/g' | grep  ^\"
"what"
"inside quotes"

EDITOR

EmacS

http://www.gnu.org/software/libtool/manual/emacs/Regexp-Replace.html

M-x replace-regex
mailto:.*@\(.*\) 
host:\1
\[.*\] []

Vi:

Replace ^M in vim :

%s/\r//g

[[Perl]]

[[PHP]]

$html='<img src="foo" >';
preg_match_all("|<img src=\"([^\"]*)\".*|", $html , $url );
print_r( $url );
print ( "url=" . $url[1][0] . "\n" ); // url=foo
eregi("MSIE", $HTTP_USER_AGENT);

[[Python]]

Ruby

thx to pok

#!/usr/bin/env ruby

puts ABOUT = "There are my git repositories"
puts "=" * ABOUT.size
puts
puts "[in #{HERE = File.dirname(__FILE__)}]"
puts

Dir["#{HERE}/**/.git"].each do |g| 
  puts "* #{g.gsub(%r{^#{HERE}/}, '').gsub(%r{/\.git$}, '')}"
end

puts

Java

s="a\n\r\n\rb\r\r\rc\n\n\rd";
document.write("#s=\""+s+"\"");
m=/\r+/g; 
r="\n"; 
s=s.replace(m,r); 
r="_";
m=/\n+/g; 
s=s.replace(m,r); 

[[Software]]

ini

# function to parse ini file (backup.ini)
#
# $1 -> file.ini
# $2 -> section
_parse_ini () {
   if [ -z "$1" ] || [ -z "$2" ]; then return 0; fi
   eval `cat $1 | \
      sed -e 's/[[:space:]]*\=[[:space:]]*/=/g' \
      -e 's/;.*$//' \
      -e 's/[[:space:]]*$//' \
      -e 's/^[[:space:]]*//' \
      -e "s/^\(.*\)=\([^\"']*\)$/\1=\"\2\"/" | \
      sed -n -e "/^\[$2\]/,/^\s*\[/{/^[^;].*\=.*/p;}"`

}

Misc

MORE

regex.txt · Last modified: 2020/09/08 20:47 (external edit)
 
Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 3.0 Unported
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki