regex

RegEx replace with calculations?

Is it possible somehow to do a RegEx-replace with a calculation in the result? (in VS2010) Such as: Grid\.Row\=\"{[0-9]+}\" to Grid.Row="eval(int(\1) + 1)" ...

How can I retrieve data between tags, in Perl ?

I'm developing a perl script. This is my input string in a file new.txt: <ID>1</ID> <CLASS>One</CLASS> <NAME>Saran</NAME> This is my code which simply prints the three lines: #!/usr/bin/perl open(FILEHANDLE1,"new.txt") or die "Can't Open: $!\n"; while($line=<FILEHANDLE1>) { print "$line"; } close FILEHANDLE1; I need it to displa...

regular expression problem

I have some XML which I want to extract via a javascript regular expression. An example of the XML is shown below: <rules><and><gt propName="Unit" value="5" type="System.Int32"/><or><startsWith propName="DeviceType"/></or></and></rules> I’m having problems extracting just the xml names “gt” and “startsWith”. For example, with the foll...

What is wrong with this boost c++ regex code???

hello #include <iostream> #include <fstream> #include <string> #include<string> #include<boost/algorithm/string.hpp> #include<boost/regex.hpp> #include <boost/algorithm/string/trim.hpp> using namespace std; using namespace boost; int main() { string robotsfile="User-Agent: *" "Disallow: /"; regex exrp( "^Disallow...

How to use a regular expression to find delimited needles within a haystack in Javascript?

In Javascript, how can I use a regular expression to iterate through a string to isolate all occurances of strings starting with a '{' and ending with a '}' character? So, for example the haystack string may be: Lorem ipsum dolor {sit} amet, consectetur adipiscing elit. {Praesent} tincidunt, sapien non ultricies posuere, justo felis {p...

Java regex get unmatched portion

I am matching a regex of the form abc.*def.*pqr.*xyz Now the string abc123def456pqr789xyz will match the pattern. I want to find the strings 123, 456, 789 with the matcher. What is the easiest way to do this? ...

Filter apache log file using regular expression

Hello, I have a big apache log file and I need to filter that and leave only (in a new file) the log from a certain IP: 192.168.1.102 I try using this command: sed -e "/^192.168.1.102/d" < input.txt > output.txt But "/d" removes those entries, and I needt to leave them. Thanks. ...

Java: Split string when an uppercase letter is found

I think this is an easy question, but I am not able to find a simple solution (say, less than 10 lines of code :) I have a String such as "thisIsMyString" and I need to convert it to a String[] {"this", "Is", "My", "String"}. Please notice the first letter is not uppercase. ...

Regex eclipse search/replace

Hello, i'm trying to find an regex for code cleanup. i want to cut of all tabs withoput any character following. \t+\n Does not work for me:/ Eclipse returns everytime "String not found" is the regex wrong? greetings ...

Best practice: Ruby/Rails Rspec regex testing

Could you tell me how to test regex-code correctly? I test my user-login attribute with following code: # user.rb class User < ActiveRecord::Base #... validates_format_of :login, :with => /^[a-zA-z0-9_.]{3,18}$/ end # user_spec.rb describe User do before(:each) do @user = Factory.build(:user) @user.save end subject...

Finding a regular expression

I have a simple question about finding a regular expression for a given language. I am given the language L where: L = {w ∈ {0, 1}* : w has exactly one pair of consecutive zeros} My first attempt at this was to try L( (0 + 1)* 00 (0 + 1)*), but I noticed the problem with that would be with where I have (0 + 1)* because if 0 is ch...

Using preg_split to split with a delimiter OR every x characters

Hello ||||overflow crowd :) I'm afraid I couldn't find an answer anywhere, so here goes: My code: $stuff = '00#00#e0#12#ff#a3#00#01#b0#23#91#00#00#e4#11#ff#a2#'; //not exact, just a random example $output = preg_split('/(?:[a-f0-9#]{12}| ff# )/', $stuff); My expectations: Array ( [0] => 00#00#e0#12# [1] => a3#00#01#b0# [...

What is the best way to match only letters in a regex?

I would really like to use \w but it also matches underscores so I'm going with [A-Za-z] which feels unnecessarily verbose and America centric. Is there a better way to do this? Something like [\w^_] (I doubt I got that syntax right)? ...

How to capture multiple arguments using a single RegEx in my Django urls.py?

I've got an application that allows you to filter data via 3 fields. I'm trying to write a RegEx in my urls.py that can capture multiple combinations without having to write-out each possible combination it it's own URL. Here's my urls.py: #urls.py urlpatterns = patterns('', # Uncomment the next line to enable the admin: (r...

PHP: preg_replace() characters and make exceptions

I need an if() function to do this: preg_replace() letters (a, b, c, etc.) except for those wrapped in tags (<p>, <b>, <span>, etc.) and exclude the letters if they are part of a certain word. $string = "<p>replace everything inside tags <b>only</b> </p>exception"; $patterns = array(); $patterns[0] = '/e/'; $patterns[1] = '/b/'; ...

Regex nested groups

I am attempting to extract all data from a file with one regex expression. Since there are optional(?,*) and repitious(*,+) expressions, it would be difficult to enumerate through the captures, at least in a readable and understandable fashion. Therefore, I am using named groups. However the data is in an XML like structure; neseted elem...

improving regex that matches {m,n}|{m,}|{,n}|{n} in the beginning of the line

Need a regex that will match either of {m,n}|{m,}|{,n}|{n} (where m and n are integer numbers) with arbitrary number of spaces in between symbols in the beginning of the line. I came up with this: ^({\s*\d+\s*,\s*\d+\s*}|{\s*,\s*\d+\s*}|{\s*\d+\s*,\s*}|{\s*\d+\s*}) While it certainly works, I was curious if there is a way to make it sh...

Regular expression to check for two of three criteria

I need to create a regular expression to match strings that satisfy any two of the following three criteria: at least one upper case letter, at lease one lower case letter, at least one number. for example the following would be the result: "TestString" = MATCH (upper & lower) "TestSTring5" = MATCH (upper, lower, & number) "teststring"...

Help me write a regex that validates a number of any size that is between two special characters?

So that means "$1$" will pass as well as "$50000000000000$" or "$12345678$" length of number doesn't matter but it must be only digits and must start and end with a '$'. ...

What is the correct regex (for PHP preg_replace) to remove empty paragraph ( <p> ) tags?

I'm working in Wordpress and need to be able to remove images and empty paragraphs. So far, I've found out how to remove images without a problem. But, I then need to remove empty paragraph tags. I'm using PHP preg_replace to handle the regex functions. So, as an example, I have the string: <p style="text-align:center;"><img src="http:...