General :: Regular Expression For Mod Rewrite - Match Directories Ape/ And Apes/
Dec 13, 2010
I have this..
RewriteRule ^(apes|ape)/(.*)$ $2?fh=$1 [L,QSA]
I only want to match the directories ape/ and apes/ but I think it is matching any directory that ends in "ape" or "apes" or maybe does it match any string containing those characters in any order? I am not great at regex, and have read alot, but still not sure if I understand this correctly.
I'm attempting to search through a rather large assortment of html files created in Word using 'save as html'. what I'm trying to do is find and delete these tags (they're causing browsers to display black diamonds with white question marks):
<span style='mso-spacerun:yes'> </span> Tags contain from 1 to 4 spaces between opening and closing. I get positive results from this:
grep <span style='mso-spacerun:yes'> filename.html but once I attempt to tell it to match any number of characters up until the next '>' symbol, it tells me I'm using an invalid regex: grep <span style='mso-spacerun:yes'>[^>]+> filename.html
I've been nose-deep in regex tutorials for the past day or so, and I'm still not understanding why this doesn't work. If I put the pattern (without backslashes) into a separate file and use `grep -f patternfile filename.html`, I get no error but no matches either. So far as I can figure, the above regex boils down to: Match the string "<span style='mso-spacerun:yes'>", followed by any number of characters that are not a ">", followed by a ">". If someone could tell me where I'm going wrong with this,
I need to use sed to edit a file that contains just one line. This should be pretty simple, but I've googled and can't seem to figure it out. I need to match everything from a certain string up until the first comma in the line. There are multiple commas in the line and my matching pattern is matching up until the last comma, not the first.
Here is what I'm trying:
As you can see it is matching up until the last comma. Seems like the .* is matching any character including the other commas. The output from this that I am hoping to achieve:
How can I get the regular expression to match from asdf: up until the first comma?
i want to grep lines which do not start with # or a blank space. like
bla bla bla bla
how do i do this? i tried grep --invert-match '^#' which gives lines not starting with # but gives me blank lines too i tried grep --invert-match '^#|^ ' which will give lines not starting with # OR not starting with blank ( which means any line including ones starting with #
On my server, logs are saved in log.gz format. I want to know what regular expression should i use to search both oracle and a particular IP, say 1.2.3.4 in a single log line ?
In the above code ^<YAHOO> search is not working (I want lines "except YAHOO"). I know that [^ab] will work for "except a,b" characters. How can I say "except word" in regular expressions?
I just want to grep for a n digit number followed by M alphabet. Generally for a three digit number i can give grep [0-9][0-9][0-9]M , but if the digits are increasing it is tough to represent them.
so I have a perl script that contains an array like this:@hostNames = (ABC123R:192.168.1.1, CBA321CBP:192.168.1.2, ZYX987R:192.168.1.3, etc firstelement"ABC123R:192.168.1.1":ABC123R is the hostname and 192.168.1.1 is it's IPaddress.I am trying to write a regular expression that will split the element with a '-' wherever there is a LETTER next to a NUMBER, like so:ABC-123-R:192.168.1.1I tried this expression below but am struggling with using regex for slightly complicated matching criteria:
What I want to achieve is, if I have following in my file: x y X z I should be able to find the pair, x Y and replace it with x a. So, basically I want to search for case sensitive 'x' but search and replace case insensitive 'y'. How should I do it? Can this be achieved with 'sed' command?
I'm trying to math all class references in a C++ file using grep with regular expression. I'm trying to know if a specific include is usuless or not, so I have to know if there is a refence in cpp. I wrote this RE that searches for a reference from class ABCZ, but unfortunately it isn't working as I espected:
^[^(/*)(//)] don't math comments in the begging of the line ( // or /* ) .* followed by any character [^a-zA-Z] do not accept any caracter before the one I'm searching (like defABCZ) []* any white space (I can have something like ABCZ var; ) [*(<:;,{& ] followed by ( * < : ; , & { (I cant get #define "ABCZ.h" or ABCZdef for example)
Well, I can get patterns like this:
class Test: public ABCZ{ class Test: public ABCZ { class Test : public ABCZ<T>
I've got a list of files that I've copied from my terminal and pasted into gedit and into OO.o writer. Since the files are all created by gedit, in each case there is both file and file~. I want to get rid of all the 'file~' lines. I thought I could do search and replace using *~, but this doesn't work.
How would I use a unix grep regular expression to find any two capital letters side by side and how would I find an expected comma in an expected spot?
There is always one occurrence of € in each line. I want the numeric value that precedes this € occurrence. The random text (before and after) may contain numbers too, so the € may be important to parse, in order to correctly identify the number to return. The last character that precedes the number to extract is always a ">" (coming from an HTML tag).
I'm writing a loganalysis application and wanted to grab apache log records between two certain dates. Assume that a date is formated as such: 22/Dec/2009:00:19 (day/month/year:hour:minute) Currently, I'm using a regular expression to replace the month name with its numeric value, remove the separators, so the above date is converted to: 221220090019 making a date comparison trivial.. but.. Running a regex on each record for large files, say, one containing a quarter million records, is extremely costly.. is there any other method not involving regex substitution? here's the function doing the convertion/comparison
I remember reading that using sed, you can do this with parentheses: s/abc(something)def/(something)else/g I can't find an explanation of how to do something like this with Awk. Say you have this in an HTML file, where (number) stands for a one or two-digit number:
Part of a perl script I am writing need to change the character at an index to upper case. Now i am new to perl and i am having some trouble getting it to do it. In c++ i would do something like
Code:
Now from what i understand the same thing is possible in perl using regular expressions. But i cant get it to work.
how do I get this regular expression to work in an if/else statement? This is just a little script for learning BASH. don't be too harsh.
This script will test if a certain number of files with 1-4 in their filename exist and print their filename. An error message will be printed if not.
# for i in `ls file[1-9]` do if [[ "$i" == *1-4 ]] ; then echo "This file, $i, ends in a number between 1-4" else echo "Error, this file, $i, does not end with a number between 1-4" fi done
I get this error. ./file_test.sh: 13: [[: not found
I'm writing a Perl script to find an old key in a file and replace it with a new codefirst the program should find the old key in the input file. here is the way I used in my script. but it doesn't work.May you please let me know what is wrong and how I can correct it?the key is stored in the file in the following format:
PHP Code: Key=("1234567" , someOtherVrable) I want 1234567
I was doing an exercise on Learning Perl, 3rd edition. (exercise chapter 10 btw) The problem asks to create a program that generates a random number and asks the user to guess. It should tell the user if the guess is lower or higher and exit if the user types either exit or quit. My code is the following:
I have something like the following in my expect script:
Code:
interact { -nobuffer -re {^s } {
[code]....
I have put the "^" anchor to match only those pattern that does not have anything before "s" e.g.
1.when I type "s" followed by "enter" key it should match.
2.if I type something like "chess" followed by "enter" key it shouldn't match. the second case is also being matched by the regular expression I have in my code.
I'm trying to math all class references in a C++ file using grep with regular expression. I'm trying to know if a specific include is usuless or not, so I have to know if there is a refence in cpp. I wrote this RE that searches for a reference from class ABCZ, but unfortunately it isn't working as I espected:
grep -E '^[^(/*)(//)].*[^a-zA-Z]ABCZ[]*[*(<:;,{& ]' ^[^(/*)(//)] don't math comments in the begging of the line ( // or /* ) .* followed by any character
[code]....
Well, I can get patterns like this:
class Test: public ABCZ{ class Test: public ABCZ { class Test : public ABCZ<T>
I wan to get this text only from the whole html code. </p></td> From the above code I want to get that english written sentence only using php preg_match or anything other which makes it possible. I've tried following so far but doesn't work