Looking for mod_rewrite regular expression feature in grep -


because picture (or example) worth more thousand words, i'll use example:

rewriterule ^/products/([0-9]+)$ /content.php?id=$1 

in rewriterule example we've got simple regular expression. $1 reference captured ([0-9]+), reference number if matching exists. possible in grep?

let's say, xml document contains following :

<sometag>somevalue</sometag> 

i extract somevalue, input second_bash_script following:

first_bash_script | grep "<sometag>\([[:digit::]]\)\+</sometag>" | second_bash_script 

is somevalue. possible extract somevalue using grep?

thanks clue!

those 2 separate questions, right?

the answer first 1 be: use sed, grep doesn't substitutions.

sed 's_^/products/\([0-9]\+\)_/content.php?id=\1_g' 

the second thing can done grep using perl regexp:

$ echo '<sometag>42</sometag>' | grep -op '(?<=<sometag>)\d+(?=</sometag>)' 42 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -