regex

(g)vim replace regex

Hi guys, I'm looking for a regex that will change sth. like this: print "testcode $testvar \n"; in printnlog("testcode $testvar \n"); I tried %s/print\s*(.\{-});/printnlog(\1);/g but gvim says print\s*(.\{-}); doesn't match. Where is my fault? Is it ok to use '*' after '\s' because later '{-};' will stop the greed? Thanks in ...

Why does m/$./m give me unexpected behavior?

In What regular expressions can never match? /$./ was given as a response. I played around with that a bit, and discovered that the following two lines of code generate different output. The second matches, but the first does not. Can anyone explain why? $ printf 'a\nb\n' | perl -0777 -ne 'print if m/$./m' $ perl -0777 -e '$_="a\nb\...

Regex implementation

I have encountered this piece of code that is supposed to determine the parent url in a hierarchy of dynamic (rewritten) urls. The basic logic goes like this: "/testing/parent/default.aspx" --> "/testing/default.aspx" "/testing/parent.aspx" --> "/testing/default.aspx" "/testing/default.aspx" --> "/default.aspx" "/defau...

TSQL Query for analyzing Text.

I have a table that has ordernumber, cancelled date and reason. Reason field is varchar(255) field and it was written by many different sales rep and really hard to group by the reason category I need to generate a report to categorize cancelation reasons. What is the best way to analyse the reasons with TSQL? Sample of reasons entered ...

Change Text in Visual Studio using Regular Expressions

Hi, As you might know,Visual Studio's Find and Replace feature allows us to use Regular Expression but I don't know how to change something like this : Math.round((document.getElementById('selectedproductPrixdock').value*document.getElementById('addxdock').value)*100)/100 to this one : (Math.round((document.getElementById('selectedp...

Does a regular expression exist for enzymatic cleavage?

Does a regular expression exist for (theoretical) tryptic cleavage of protein sequences? The cleavage rule for trypsin is: after R or K, but not before P. Example: Cleavage of the sequence VGTKCCTKPESERMPCTEDYLSLILNR should result in these 3 sequences (peptides): VGTK CCTKPESER MPCTEDYLSLILNR Note that there is no cleavage after ...

mod_alias subdirectory replacement

I am using RewriteMatch to redirect all traffic from subdir1 to subdir2, while keeping all other parts of the url the same. So for instance, http://www.mydomain.com/subdir1/ would redirect to http://www.mydomain.com/subdir2/ I am using this rule: RedirectMatch 302 /subdir1/.* /subdir2/$1 which works for the url http://www.m...

perl precompiled regex question

Do I really get any benefit out of doing the following (as opposed to just putting the actual regex in place of the ${pcr} in both if statements)? (alot more lines are in the real data set but just using DATA for example. my $defs = 0; my $tests = 0; my $pcr = qr/\s*[\/\\]?\s*/; while (<DATA>) { $defs = ($1 ? 0 : 1) if /<(${pcr})d...

Is there a Perl shortcut to count the number of matches in a string?

Suppose I have: my $string = "one.two.three.four"; How should I play with context to get the number of times the pattern found a match (3)? Can this be done using a one-liner? I tried this: my ($number) = scalar($string=~/\./gi); I thought that by putting parentheses around $number, I'd force array context, and by the use of scal...

How can you detect if two regular expressions overlap in the strings they can match?

I have a container of regular expressions. I'd like to analyze them to determine if it's possible to generate a string that matches more than 1 of them. Short of writing my own regex engine with this use case in mind, is there an easy way in C++ or Python to solve this problem? ...

Xpath replace function, processing matches

I'm writing a function to "title case" strings e.g. "this is a title" to "This is a Title." The following line doesn't work because the regex group reference is lost (or so I assume). Is there an easy way to uppercase my matching letter in the replace function? replace( $input, '\b[a-z]' , upper-case('$0')) ...

Capture a part of a string that does not match another group (C# Regex)

Hello. I am working on a project that requires the parsing of "formatting tags." By using a tag like this: <b>text</b>, it modifies the way the text will look (that tag makes the text bold). You can have up to 4 identifiers in one tag (b for bold, i for italics, u for underline, and s for strikeout). For example: <bi>some</b> text</i>...

compairing some pattern with regular expression C#

i am parsing binary file. File size can be large. i want to search a some pattern in that file. the string is anynumber 0 obj<< any alpha,symbol,digit...anything >>endobj Bold text indicates compulsory string. So, My QUESTION is - should i do it by regular expression or search it by coding. After that i want to store it in a...

PHP Dynamic Regular expression?

Hi all, I'm relativly new to regular expressions but I managed to create a working expression to validate dates (without leap years, and assuming people enter a valid 30 or 31 digit for a month). This is the expressen: /^\d[1-31]{2}\-\d[1-12]{2}\-\d[1900-2009]{4}$/ But I would like to have a dynamic regular expression like: $yearSpa...

How to use regex in a c#, specifically getting the data inside a double quote?

For example, we just want to get the data inside double quotes from a list of strings: String result = string.Empty; List<string> strings = new List<string>(); strings.add("string=\"string\""); strings.add("stringwithspace=\"string with space\""); strings.add("untrimmedstring=\" untrimmed string\""); strings.add("anotheruntrimmedstring...

function that returning index position of string after match found C#

I have strings of 15 characters long..i am performing some pattern matching on it with the use of regular expression. i want to know the position of string where the isMatch() function returns true. Is there is any function that return index position of a string I want to perform some operation on that index. ...

how to write regular expression in C#

I want to check if my string holds following value or not.. My condition is 48-57(1 or more time)32(or)10(or)13(then)48(then)32(or)10(or)13(then)111981066060 how to write regular expression for above condition. bracket text indicates occurrence. I tried it but it wont work.Thanks in advance. Samples: 4850324810111981066060 501...

Javascript "Invalid Date" error in Safari.

Hello, I've been trying to debug a script of mine and I can't get my head around what's wrong with this: var date = new Date("19871104071535".replace( /^(\d{4})(\d\d)(\d\d)(\d\d)(\d\d)(\d\d)$/, '$4:$5:$6 $2/$3/$1' )); alert(date); It works in Firefox, IE, Chrome but Safari gives me an "Invalid Date" error. Any ideas? ...

Sed: Replace all whitespace with a line break/paragraph mark to make a word list.

I am trying to vocab list for a greek text we are translating in class, I want to be able to replace every space or tab character with a paragraph mark, so that every word appears on it's own line. Can anyone give me the sed command, and explain what it is that I'm doing? I'm still trying to figure sed out. ...

Simple Regular Expression to return text from Wordpress title - qtranslate plugin

Hello all, I am using qtranslate wordpress plugin to store blog content in multiple languages. Now I need to extract content from qtranslate tags. $post_title = "<!--:en-->English text<!--:--><!--:it-->Italian text<!--:-->"; What would be the php code & regular expression to return text and language from this string? Thanks a lot! ...