regex

Problem with redirecting *.example.com & example.com to www.example.com for HTTPS

We have a site I'll call example.com. Most of the time you see http://www.example.com and sometimes we redirect you to https://www.example.com. We want to redirect anyone going to http://example.com or http://*.example.com to http://www.example.com, and the same for https. (It's mainly to avoid the alert you get if you go to https://exa...

JavaScript - checking for any lowercase letters in a string

Consider a JavaScript method that needs to check whether a given string is in all uppercase letters. The input strings are people's names. The current algorithm is to check for any lowercase letters. var check1 = "Jack Spratt"; var check2 = "BARBARA FOO-BAR"; var check3 = "JASON D'WIDGET"; var isUpper1 = HasLowercaseCharacter...

How to extract block of XML from a log file on Linux

I have a log file that looks like the following: 2010-05-12 12:23:45 Some sort of log entry 2010-05-12 01:45:12 Request XML: <RootTag> <Element>Value</Element> <Element>Another Value</Element> </RootTag> 2010-05-12 01:45:32 Response XML: <ResponseRoot> <Element>Value</Element> </ResponseRoot> 2010-05-12 01:45:49 Another log entry What...

ruby regex links not already in anchor tag

I am using ruby 1.8.7. I am not using rails. How do I find all the links which are not already in anchor tag. s = %Q{ <a href='www.a.com'><b>www.a.com</b></a> www.b.com <div>www.c.com</div> } The output of above string should be www.b.com www.c.com I know "b" tag before www.a.com complicates the case but that's what I have to wor...

Confusion in RegExp Reluctant quantifier? Java

Hi, Could anyone please tell me the reason of getting an output as: ab for the following RegExp code using Relcutant quantifier? Pattern p = Pattern.compile("abc*?"); Matcher m = p.matcher("abcfoo"); while(m.find()) System.out.println(m.group()); // ab and getting empty indices for the following code? Pattern p = Patt...

php: trim br tags from the beginning of a string?

I know that: preg_replace('<br\s*\/?>', '', $string); will remove all br tags from $string... How can we remove all <br><br/><br /> tags only if they are in the very beginning of $string? ($string in my case is html code with various tags...) ...

C# regex. Optional match after string

I have an input like this test1.test2.part01 which I want to strip away to test1.test2. The only thing i know is that it will end with partxx and probably a dot before the partxx. However, it will not always be a apart. Another example of input might be testas1.tlp2.asd3.part10 which ofcourse should be stripped to testas1.tlp2.asd3. I'...

Regex Searching in Emacs

I'm trying to write some Elisp code to format a bunch of legacy files. The idea is that if a file contains a section like "<meta name=\"keywords\" content=\"\\(.*?\\)\" />", then I want to insert a section that contains existing keywords. If that section is not found, I want to insert my own default keywords into the same section. I've...

How to look for files not having the word TEST using ack

I love ack. I need to search for 'foo' in all the files except the test files. ack has option -G to specify regex. However I am not sure how do I write regex for the condition that look for all files but ignore files with word 'test'. ...

Regular expression of unicode characters on string

I'm working in C# doing some OCR work and have extracted the text I need to work with. Now I need to parse a line using Regular Expressions. string checkNum; string routingNum; string accountNum; Regex regEx = new Regex(@"\u9288\d+\u9288"); Match match = regEx.Match(numbers); if (match.Success) checkNum = match.Value.Remove(0, 1).R...

python regular expressions, how to extract longest of overlapping groups

Hi How can I extract the longest of groups which start the same way For example, from a given string, I want to extract the longest match to either CS or CSI. I tried this "(CS|CSI).*" and it it will return CS rather than CSI even if CSI is available. If I do "(CSI|CS).*" then I do get CSI if it's a match, so I gues the solution i...

CSV Import Split by Comma - what to do about quotes?

I have a CSV file I'm importing but am running into an issue. The data is in the format: TEST 690, "This is a test 1, 2 and 3" ,$14.95 ,4 I need to be able to explode by the , that are not within the quotes... ...

Help with specific Regex: need to match multiple instances of multiple formats in a single string.

I apologize for the terrible title...it can be hard to try to summarize an entire situation into a single sentence. Let me start by saying that I'm asking because I'm just not a Regex expert. I've used it a bit here and there, but I just come up short with the correct way to meet the following requirements. The Regex that I'm attemptin...

SED whitespace removal within a string

I'm trying to use sed to replace whitespace within a string. For example, given the line: var test = 'Some test text here.'; I want to get: var test = 'Sometesttexthere.'; I've tried using (\x27 matches the '): sed 's|\x27\([^\x27[:space:]]*\)[[:space:]]|\x27\1|g but that just gives var test = 'Sometest text here.'; Any ideas...

Regex to match anything (including the empty string) except a specific given string.

I'd like to test whether a string contains "Kansas" followed by anything other than " State". Examples: "I am from Kansas" true "Kansas State is great" false "Kansas is a state" true "Kansas Kansas State" true "Kansas State vs Kansas" true "I'm from Kansas State" false "KansasState" true ...

How to convert a PCRE to a POSIX RE?

This interesting question http://stackoverflow.com/questions/2837267/ concerned how to do a negative look-ahead in MySQL. The poster wanted to get the effect of Kansas(?! State) because MySQL doesn't implement look-ahead assertions, a number of answers came up the equivalent Kansas($|[^ ]| ($|[^S])| S($|[^t])| St($|[^a])| Sta($|[^t])...

Javascript regex URL matching

I have this so far: chrome.tabs.getSelected(null, function(tab) { var title = tab.title; var btn = '<a href="' + tab.url + '" onclick="save(\'' + title + '\');"> ' + title + '</a>'; if(tab.url.match('/http:\/\/www.mydomain.com\/version.php/i')) { document.getElementById('link').innerHTML = '<p>' + btn + '</p>'...

In PHP how do I complete a regex that returns only what was grouped

I want to perform a regex using grouping. I am only interested in the grouping, its all I want returned. Is this possible? $haystack = '<a href="/foo.php">Go To Foo</a>'; $needle = '/href="(.*)">/'; preg_match($needle,$haystack,$matches); print_r($matches); //Outputs //Array ( [0] => href="/foo.php"> [1] => /foo.php ) //I want: //A...

SQL with Regular Expressions vs Indexes with Logical Merging Functions

Hello All, I am trying to develop a complex textual search engine. I have thousands of textual pages from many books. I need to search pages that contain specified complex logical criterias. These criterias can contain virtually any compination of the following: A: Full words. B: Word roots (semilar to stems; i.e. all words with certa...

Extract http://www.website.com from http://www.website.com/08/2010/super-cool-article

I suck at regex, I only managed to get so far preg_match("/http:\/\//", $url). I need this for a php script ...