regex

Regex for /pattern/opt syntax?

How do i write a regex that matches the syntax in either perl ruby javascript The syntax is like /my pattern here/modifiers where modifiers are i, g and other single letters. I wrote the below however that wouldn't allow me to escape escape / with using . AFAIK i can write /Test\/Pattern/i in those languages to match the text Test/Pat...

What is the Ruby regex to match a string with at least one period and no spaces?

What is the regex to match a string with at least one period and no spaces? ...

How do I unescape some backslashes but not all in Perl?

Hello. I am using tinyperl with the following script: @lines=<STDIN>; foreach (@lines) { s/\\(.)/($1 eq '"' or $1 eq '\\') ? $1 : '\\' . $1/eg; print; } I would like each backslash to be considered only with the following character, and remove the backslash only if the following character is a double quote or another backslash...

Parsing PDF file using Regular expresions in Python

Hello, I am trying to parse some object elements from a PDF file using re module of Python. My goal is to parse each PDF object using a regular expression. A PDF object example is the following: 1 0 obj << /Type /Catalog /Pages 2 0 R >> endobj 2 0 obj << /Type /Pages /Kids [ 3 0 R ] /Count 1 >> endobj ... When I u...

How can I select certain elements from a Perl array?

I want to search for all elements in an array which have the same starting set of characters as an element in another array. To make it clear: @array = ("1a","9","3c"); @temp =("1","2","3"); I want to print only 1a and 3c. When I try to use the following program it prints out all the elements in the array instead of the two I want: f...

Insert a string into an existing RegExp in Javascript?

Possible Duplicate: passing variable to a regexp in javascript I have a variable: resource = "user"; I want to insert that variable into a predefined RegExp (replacing variable beneath): /^\/variable\/\d+$/ How could I do that? ...

sed regex, work on substrings and not on whole line

suppose to have the following string: commandone{alpha} commandtwo{beta} {gamma}commandthree commandtwo{delta} and I want to abtain: commandone{alpha} beta {gamma}commandthree delta well I'm triying with regex and sed, I can easily find if is it present the pattern I look for /commandtwo{.*}/ but not erasing commandtwo and the foll...

How can I count the amount of spaces at the start of a string in Perl?

How can I count the amount of spaces at the start of a string in Perl? I now have: $temp = rtrim($line[0]); $count = ($temp =~ tr/^ //); But that gives me the count of all spaces. ...

Regex to match a string after colon

Input string is something like this: OU=TEST:This001. We need extra "This001". Best in C#. ...

regular expressions to add a slash to the end of a generic string of words

I'm in notepad++ and I need to add a / right before the closing > in the following line: <meta name="description" content="*****"> the ***** above is a bunch of text that I need left in place, and it changes from page to page, thus my need for some find / replace method that is superior to what I would normally be capable of. I assu...

Regexp to check if parentheses are balanced

Possible Duplicate: Can regular expressions be used to match nested patterns? I am writing a regexp to check if the input string is a correct arithmetic expression. The problem is checking if there are enough opening and closing parentheses. Expressions: (1) (((1) ((1)))) I think lookahead and lookbehind are useful here b...

Regex - how to make my regex not pass when the string is blank

Hi, I have a regex that will validate to make sure I have a number. but it passed if the string I'm checking is "" as well. how can I make a "" fail? ^(\\d|-)?(\\d|,)*\\.?\\d*$ ...

Regex to match 010101

Is it possible to have a regex to match a string with alternating 0 and 1? It can end in 0 or 1 and length is arbitrary. ...

Java Regexp question

There is a web site, what i want to parse. The source is the following <tr> <td><a href="http://www.z104.com/"&gt;&lt;b&gt;WNVZ&lt;/b&gt;&lt;/a&gt; - Z104</td> <td>Norfolk</td> <td>Virginia</td> <td><img src="mp3.gif" alt="MP3" width="12" height="12"></td> <td><a href="http://provisioning.streamtheworld.com/pls/WNVZFM.pls"&gt;64 ...

RegExp.exec not returning global results

According to MDC https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/RegExp/exec the following code should log each of the global matches for this regexp. var str = "(^|\\+)(1\\+1)($|\\+)"; var regex = new RegExp(str, "g"); var result; var testString = "1+1+1"; while ((result = regex.exec(testString)) != null) { con...

VIM search and replace - replace string that is found on particular lines only

So I have a bunch of lines like this - $ns duplex-link n1 n2 10mb 10ms DropTail $ns duplex-link-op n1 n2 10mb 10ms queuePos 0.5 $ns duplex-link n2 n3 10mb 10ms DropTail $ns duplex-link-op n2 n3 10mb 10ms queuePos 0.5 $ns duplex-link n3 n4 10mb 10ms DropTail $ns duplex-link-op n3 n4 10mb 10ms queuePos 0.5 Now here's the problem. I wan...

Convert street address from string to columns - Regex ?

I have a list of 350 addresses in a single column excel file that I need to import to a SQL table, breaking the data into columns. content of the Excel cells is such as this one Courtesy Motors 2520 Cohasset Rd - Chico, CA 95973-1307 530-893-1300   What strategy should I apply to import this in a clean fashion? I was thinking NAME ...

Using named groups in .NET Regex

I'm new to .NET and having a hard time trying to understand the Regex object. What I'm trying to do is below. It's pseudo-code; I don't know the actual code that makes this work: string pattern = ...; // has multiple groups using the Regex syntax <groupName> if (new Regex(pattern).Apply(inputString).HasMatches) { var matches = new...

Using conditional replace in C# Regular Expressions for CSS minification

Hey guys, I am making an application using C# in Visual Studio that minifies CSS code. Now I came across a piece of code that strips all prefixes for the # ID selector. strCSS = Regex.Replace(strCSS, @"[a-zA-Z]+#", "#"); However, this would also remove any class names in front the ID selector. For example, #interior .field#user-comme...

PHP Regex to match a list of words against a string

I have a list of words in an array. I need to look for matches on a string for any of those words. Example word list company executive files resource Example string Executives are running the company Here's the function I've written but it's not working $matches = array(); $pattern = "/^("; foreach( $word_list as $word ) { $p...