regex

Need help understanding Javascript's .match method

Hello all, I understand that .match() returns an array of the matches, or null if none are found. But how do I go about accessing the values of capturing groups used with .match? For example: var val = whatever.match('(?:^|;) ?' + stuff + '=([^;]*)(?:;|$)'); Assuming the regular expression matches more than once, how do I access th...

PHP: question about preg_replace()

Hi, i have found this: $text = preg_replace('/\W+/', '-', $text); Anyone can tell me what exactly do that? There is no information about what '/\W+/' means.. Regards Javi ...

Google Analytics funnel goals not working?

I have a goal set up that is roughly as follows: product page -> first page order form -> second page order form -> thank you page I have checked the regex for all of the above by searching the filters in Top Content and have checked over all of them a few times. On the funnel visualization page, every number listed is zero. On the go...

Matching double char delimited strings with regular expressions

Suppose you want to match text that is delimited by double characters like so: a = << Hello World! >> The regular expression /<<(.*)>>/ would seem to do it, but unfortunately when these can be repeated greedy matching gets too much: a = << Hello World! >> b = << Goodbye World! >> The previous regexp will capture Hello World! >> ...

PHP: regular expression to replace from a string everything except for alpha numeric characters

Hi, I need to clean a string and make sure it contains alpha numeric characters only. I've come up with the following code that for some reason fails $string = 'aaa`bbb!!'; $string = preg_replace("#[^a-zA-z0-9]*#", "", $string); echo $string;die; The output I receive is aaa`bbb while I expect aaabbb. Could you please h...

How do I search from the bottom up using a regular expression?

Here is an example of the type of text file I am trying to search (named usefile): DOCK onomatopoeia DOCK blah blah blah DOCK blah DOCK blah blah blah onomatopoeia blah blah blah blah blah DOCK DOCK blah blah DOCK blah onomatopoeia I am using a finditer statement to find everything between DOCK and onomatopoeia as follows: re.finditer...

php preg_match_all, regex, extract specific value

I'm trying to extract the users who ask questions on a classified ad website(http://trademe.co.nz/Trade-Me-Motors/Cars/Toyota/Hiace/auction-300294634.htm) . For some reasons the pattern which I'm using is not working always so I would appreciate if you will help me with a perfect regex Here is my current code /get memberid of the que...

Python : match string inside double quotes and bracket

Hello,I want to match text inside double quotes and bracket as two groups by use regex, How can I do that? from “作為”(act) ,用於罪行或民事過失時,包括一連串作為、任何違法的不作為和一連串違法的不作為; “行政上訴委員會”(Administrative Appeals Board) 指根據《行政上訴委員會條例》(第442章)設立的行政上訴委員會;(由1994年第6號第32條增補) “成人”、“成年人”(adult)* 指年滿18歲的人; (由1990年第32號第6條修訂) “飛機”、“航空器”(aircraft) 指任何可憑空氣的反作用而在大氣中獲...

How to regex in python?

I am trying to parse the keywords from google suggest, this is the url: http://google.com/complete/search?output=toolbar&amp;q=test I've done it with php using: '|<CompleteSuggestion><suggestion data="(.*?)"/><num_queries int="(.*?)"/></CompleteSuggestion>|is' But that wont work with python re.match(pattern, string), I tried a few b...

Powershell using a regex to create a new hash table object

I'm trying to parse a file that contains blocks of text in this format(there can be 1-n of these): ----------------------------------------------------------- KB Article Number(s): 2028769, 2072493, 2120979, 2143880, 2163958, 2163980, 980653, 980883, 981155, 981867, 982321, 982850 Language: All (Global) Platform: x64 Location: (http://f...

Help For A Simple Regular Expression

Hi, i want to extract 34 from this string. How Can i done that ? (i will use javascript) #project_maincategory=3&project_subcategory=34&project_tags[]=70&project_tags[]=71&created_in=30 ...

How to replace upper case with lower case using regex?

Hello, i need to replace upper case letter in variable name with lower case letter and add space For example: "NotImplementedException" should be "Not implemented exception" "UnhandledException" should be "Unhandled exception" Thanks ...

preg replace to remove bbcode quote

Could someone give me an example of how to I can remove [QUOTE=author;3095231] Author being the authors name, and 3095231 being the post. I want to use preg replace, or anything similar but not sure how and was wondering for an example, I believe it would be something like [QUOTE=(.+?)] and i don't know the rest. ...

JavaScript rejects all my RegExs, how come?

Hi, I have this at the moment, (I found the code on here). var exp = /(\b(https?|ftp|file):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/ig; someText.replace(exp, "<a href='$1'>$1</a>"); It will replace any http://URL in someText with a proper <a href> But i also require it to match www. without the http. I found ...

Regular expression for length validation in email address.

We have a textbox which accepts comma separated email address. The regular expression is ^(\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*\s*[,]?\b)*$. However now I am unable to add a length validation to this expression. Each email address should not be more than 150 characters. I have tried ^((\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-....

Javascript replace method, replace with "$1"

I'm reading Sitepoints 2007 book "Simply Javascript" and I encountered some code I just can't understand. It's the following code: Core.removeClass = function(target, theClass) { var pattern = new RegExp("(^| )" + theClass + "( |$)"); target.className = target.className.replace(pattern, "$1"); target.className = target.clas...

improving regular expression to match all "http" only urls very neatly .

i have tried below given expressions. (http:\/\/.*?)['\"\< \>] (http:\/\/[-a-zA-Z0-9+&@#\/%?=~_|!:,.;\"]*[-a-zA-Z0-9+&@#\/%=~_|\"]) the first one is doing well but always gives the last extra character with the matched urls . Eg: http://domain.com/path.html" http://domain.com/path.html&lt; Notice " < I don't want them with ...

PHP preg_replace - finding the replacement from an array using the match as the key

I have a string which can contain multiple matches (any word surrounded by percentage marks) and an array of replacements - they key of each replacement being the match of the regex. Some code will probably explain that better... $str = "PHP %foo% my %bar% in!"; $rep = array( 'foo' => 'does', 'bar' => 'head' ); The desired result ...

Using the Perl split function, but keeping certain delimiters

I have a string that I need to split on a certain character. However, I only need to split the string on one of those characters when it is flanked by digits. That same character exists in other places in the string, but would be flanked by a letter -- at least on one side. I have tried to use the split function as follows (using "x" ...

Help with regular expression and grep in Linux terminal.

I'm new to regular expressions and grep, but I've been trying to learn it to help me when using console tools. I have to use cvs, and when I update some files, I don't need to see files that were't updated or with *.pyc extension for example. So, I created a script that calls: cvs update -d | grep -v 'pyc$' | grep -v '^\?' First ques...