regex

How to have variable as regex in perl

I think this question is repeated but searching wasn't helpful for me. my $pattern = "javascript:window.open\('([^']+)'\);"; $mech->content =~ m/($pattern)/; print $1; I want to have an external $pattern in the RegEx. How can I do this? The current one returns: Use of uninitialized value $1 in print at main.pm line 20. ...

Extracting information from a SPARQL query using regular expressions

I am having a hard time creating a regular expression that extracts the namespaces from this SPARQL query: SELECT * WHERE { ?Vehicle rdf:type umbel-sc:CompactCar ; skos:subject <http://dbpedia.org/resource/Category:Vehicles_with_CVT_transmission&gt;; dbp-prop:assembly ?Place. ?Place geo-ont:parentFeatu...

regex matching multiple values when they might not exist

I am trying to right a preg_match_all to match horse race distance. My source lists races as: xmxfxy I want to match the m value, the f value, the y value. However different races will maybe only have m, or f, or y, or two of them or even all three. // e.g. $raw = 5f213y; preg_match_all('/(\d{1,})m|(\d{1,})f|(\d{1,})y/', $raw, $distan...

Regex conditional

How would I write a RegEx to: Find a match where the first instance of a > character is before the first instance of a < character. (I am looking for bad HTML where the closing > initially in a line has no opening <.) ...

Can some please explain this elisp regexp

Can some please explain the following regexp, which I found in ediff-trees.el as a specification for which files/directories to exclude from its comparison process. "\\`\\(\\.?#.*\\|.*,v\\|.*~\\|\\.svn\\|CVS\\|_darcs\\)\\'" Although I am somewhat familiar with regular expressions encountering this elisp string-based variant has throw...

Regex replacements inside a StringBuilder

I'm writing the contents of a text file to a StringBuilder and I then want to perform a number of find/replace actions on the text contained in the StringBuilder using regular expressions. I've run into a problem as the StringBuilder replace function is not capable of accepting regular expression arguments. I could use Regex.Replace o...

Remove all but valid characters

Valid characters include the alphabet (abcd..), numbers (0123456789), spaces, ' and ". I need to strip any other characters than these from a string in PHP. Thanks :) ...

reg ex newby - how do you specify to match a characters but not include it in the output?

Really simple situation: Eg. in this string: my dog said "woof" today I would like to get the string in quotes, but without the quotes... --- more detail --- Unfortunately the regex is via 3rd party software so I don't know the underlying engine. Here's the string: href="http://pagingdrgupta.blogs.cnn.com/2010/08/17/dengue-fever...

Short Question on Case sensitivity; Php

This tests a textarea input agains bad words... $bad_words = array('bad', 'words') foreach( $bad_words as $bad ){ if( stristr($posted, $bad) !== FALSE ) { $contains_bad_words = TRUE; } } Now is there any way to make this match 'bad', 'BAD', 'Bad', 'BaD' etc without having to write it into the array in all different cases (La...

How to create a regexp that matches a pattern except for some strings in Ruby?

I work in Ruby, and have to create a single regexp for the following task, as I'm working with someone else's gem that uses this regexp to match fields to be worked on in a text file. I need to match beginning of string, any set of characters, and underscore, then any multi-digit integer that is not 1,2, 9, or 10, and end of string. I.e....

Codeigniter and preg_replace

I use Codeigniter to create a multilingual website and everything works fine, but when I try to use the "alternative languages helper" by Luis I've got a problem. This helper uses a regular expression to replace the current language with the new one: $new_uri = preg_replace('/^'.$actual_lang.'/', $lang, $uri); The problem is that I ha...

boost regex matching question

Hi, I want to test a regular expression with boost: const wregex regex_comment(L"^\\s*#.*"); //regexpr for comment My problem - it does not match a widestring consisting of: #This is a comment can someone give me a hint why or where I can look for the error? hm - it seems to work in the non-Unicode version. I'm using boost 1.42, s...

Regex match for beginning of multiple words in string

In Javascript i want to be able to match strings that begin with a certain phrase. However, I want it to be able to match the start of any word in the phrase, not just the beginning of the phrase. For example: Phrase: "This is the best" Need to Match: "th" Result: Matches Th and th EDIT: \b works great however it proposes another ...

What is a regular expression and C# code to strip any html tag except links?

I'm creating a CLR user defined function in Sql Server 2005 to do some cleaning in a lot of database tables. The task is to remove almost all tags except links ('a' tags and their 'href' attributes). So I divided the problem in two stages. 1. creating a user defined sql server function, and 2. creating a sql server script to do the upda...

PHP And Regular Expression

I need to check if any strings follow the same format as these. Val-Pak *Client Referral* Gift Certificate It needs to be done in regular expression. I can't find how to include the * and -. Thanks ...

Replacing words with tag links in PHP

I have a text ($text) and an array of words ($tags). These words in the text should be replaced with links to other pages so they don't break the existing links in the text. In CakePHP there is a method in TextHelper for doing this but it is corrupted and it breaks the existing HTML links in the text. The method suppose to work like this...

How do I find only whole words using re.search?

I have a list of words built from different HTML pages. Instead of writing rule after rule to strip out different elements, I am trying to go through the list and say if it's not a full word with only alpha characters, just move on. This is not working. for w in words: if re.search('\b[a-zA-Z]\b', w) == None: continue I...

How do you use non captured elements in a Javascript regex?

I want to capture thing in nothing globally and case insensitively. For some reason this doesn't work: "Nothing thing nothing".match(/no(thing)/gi); jsFiddle The captured array is Nothing,nothing instead of thing,thing. I thought parentheses delimit the matching pattern? What am I doing wrong? (yes, I know this will also match in...

combination regex and php still not work

hey all.i'm newbie at this problem.i have this data in table result: item range_code class red 123x0001-123x0500 A blue 123x0021-123x0100 //if null read zero green 123x0001-123x0300 b i want the result like: item qty ...

Regular Expression 'Split' function

Hi, I'm new to this site, and new to Python. So I'm learning about Regular Expressions and I was working through Google's expamples here. I was doing one of the 'Search' examples but I changed the 'Search' to 'Split' and changed the search pattern a bit just to play with it, here's the line print re.split(r'i', 'piiig') (notice th...