regex

Regular expression to change user input

I am doing a search on my database. If the user enters eg. "foo bar" I want to display rows that have both "foo" AND "bar". My SQL syntax looks like this: SELECT * FROM t1 WHERE MATCH (t1.foo_desc, t2.bar_desc) AGAINST ('+foo* +bar*') How can I change the user input "foo bar" into "+foo* +bar*" using a regular expression in PHP? ...

Need help on Apache htaccess redirect rule

I need to redirect from path /articles/20090425-swine-flu-kills.html to /2009/04/swine-flu-kills.html In the original path, the digits after articles are the dates in yyyymmdd format. This to convert to "/yyyy/mm/" in the new path. I suppose need some regex but I am not sure how. Would appreciate help. Thanks ...

regex: matching phrases without a > or white space

I'm parsing some html using regex and I want to match lines which start with a word without any html tags while also removing the white space. Using c# regex my first pattern was: pattern = @"^\s*([^<])"; which attempts to grab all the white space and then capture any non '<' characters. Unfortunately if the line is all white space be...

Regex with unusual characters

I'm trying to come up with some regex to handle the # sign. Example, #PRODUCT_143# If the input were #PRODUCT_143, the regex #PRODUCT_(\d*$) matches and returns 143 as the match. But adding the # to the end of both the input and the regex causes it to break. what do I need to do here to get this to match? ...

How can I remove linebreaks with a Perl regex?

when I run: perl -e '$x="abc\nxyz\n123"; $x =~ s/\n.*/... multiline.../; printf("str %s\n", $x);' I expect result to be: str abc... multiline... instead I get str abc... multiline... 123 Where am I going wrong? ...

negative look behind with unknown number of spaces

Using c# regex I'm trying to match things in quotes which aren't also in brackets while also ignoring any white space: "blah" - match ("blah") - no match ( "blah") - no match ( "blah") - no match I've got (unescaped): "(?<=[^(]\s")(.*?)" which works with the first three but I can't work out how to deal with more than one space be...

regex: matching same expression unknown number of times

Hi, With the help of some of the guys here I have some regex to match strings in quotes that aren't in brackets: "one" - matches ("two") - doesn't match Is it possible to repeat the match so the input: "one" ("two") "three" would return one and three? The only thing I can think of doing is capturing whatever is left over and reproc...

How do I perform a Javascript match with a pattern that depends on a variable?

The current implementation of Remy Sharp's jQuery tag suggestion plugin only checks for matches at the beginning of a tag. For example, typing "Photoshop" will not return a tag named "Adobe Photoshop". By default, the search is case-sensitive. I have slightly modified it to trim excess spaces and ignore case: for (i = 0; i < tagsToSear...

Using regex to fix xml content

I am attempting to fix some bilingual xml files using regular expressions to match known patterns of erroneous content and substituting the correct values. Most of the problems in the xml files can be considered typos or redundant data. I do have a text processing tool that works in software without any regex support, but the whole situ...

How to use UNIX find to find (file1 OR file2)?

In the bash command line, I want to find all files that are named foo or bar. I tried this: find . -name "foo\|bar" but that doesn't work. What's the right syntax? ...

c# regular expression problem

I have this regular expression that extracts meta tags from HTML documents but it gives me errors while I incorporate it in my web application. the expression is @"<meta[\\s]+[^>]*?name[\\s]?=[\\s\"\']+(.*?)[\\s\"\']+content[\\s]?=[\\s\"\']+(.*?)[\"\']+.*?>" ; is there anything wrong with it? ...

How to use regex to extract groups of question-answer data from html files?

How can I use a regular expression to extract groups of html that will be formatted like this: . . .irrelevant html... <b>Question 6</b><br> lots of text <p> lots of text <p> <br> <b>Answer 6</b><br> lots of text <p> lots of text <p> lots of text <p> more text <p> <HR> <IMG SRC="/images/image.jpg" alt="alt text" width...

Regex for set

I'd like some help for detecting the following expressions with RegEx string "(x/x)" where x is any number from 0-999. string "x of x" where x is any number from 0-999. Typically, the string is a marker for a set, i.e. 4 of 10 things, or (3/5) where the first number is the item and the second number is the total. Thanks ...

Javascript Regex Only Textbox

I was able to find the solution for this in c# / .net but not for regular web html. If there's already an answer let me know and i'll close question. How to create a text box that only will allow certain characters (ex. alphanumeric) based on a given regex (ex. [a-zA-Z0-9])? So if a user tries to enter anything else, paste included, it ...

.htaccess redirect after replace a word?

Hello, I need to use .htaccess file to replace a world in URL something like this: example URL: http://example.com/oldword/test-page.html redirect to: http://example.com/newword/test-page.html how can I use mod_rewrite to redirect every URL containt "/oldword/" to the same URL after replacing that word? ...

Correcting Wrong Marker Folding in VIM

I mistakenly did marker folding to my .vimrc: {{{8 #CS something.. }}}8 {{{9 #Math ... }}}9 ... many more! I need to switch the format to "#SOMETHING {{{NUMBER" like: #CS {{{8 something.. }}}8 #Math {{{9 ... }}}9 ... many more! What is wrong in the following code: :%s$/({{{\d/) /(#[:alpha:]/)$\2 \1$g [Solution] %s$\(...

What is the most difficult /challenging regular expression you have ever written ?

Whether Regex use with C#, VB.NET, Perl or any language. So, regardless of the language you use, share with us one or two of your challenging regular expression. ...

Are Regular Expressions useful for a Web Designer (XHTML/CSS)?

Are Regular Expressions useful for a Web Designer (XHTML/CSS)? Can a web designer get any help if they learn regular expressions? ...

What does the regular expression $$ mean?

what does the regular expression $$ evaluate to? ...

How can I strip a substring from a string with a regular expression?

Hi, I have a classpath, something like: myproject/classes;myproject/lib/somecrab.zip;myproject/lib/somelib1.jar;myproject/lib/somelib2.jar;myproject/lib/somelib3.jar; Now I would like to clean up this classpath and throw away somethings which I don't want anymore. Hence in this case the classpath should look something like myproject/...