regex

Regex: To pull out a sub-string between two tags in a string

If i have a file like the following: Data Data Data [Start] Data i want [End] Data Whats the regex to pull out the data between the [start] and [end] tags...

How can I get at the matches when using preg_replace in PHP?

I am trying to grab the capital letters of a couple of words and wrap them in spans. I am using preg_replace, but it's not outputting anything. preg_replace("/[A-Z]/", "<span class=\"initial\">$1</span>", $str)...

How far should one take e-mail address validation?

I'm wondering how far people should take the validation of e-mail address. My field is primarily web-development, but this applies anywhere. I've seen a few approaches: simply checking if there is an "@" present, which is dead simply but of course not that reliable. a more complex regex test for standard e-mail formats a full regex ag...

Learning Regular Expressions

I already know the basics of RegEx but I'm not sure where to go from here, I'm looking for both a good and above all easy to understand guide but I am also looking for things to use RegEx's for, it's all well and good reading about it but if you never use them then they will not stick in your mind. I have already found regular-expressio...

Why is this regular expression faster?

I'm writing a Telnet client of sorts in C# and part of what I have to parse are ANSI/VT100 escape sequences, specifically, just those used for colour and formatting (detailed here). One method I have is one to find all the codes and remove them, so I can render the text without any formatting if needed: public static string StripS...

What are good regular expressions?

I have worked for 5 years mainly in java desktop applications accessing Oracle databases and I have never used regular expressions. Now I enter Stack Overflow and I see a lot of questions about them; I feel like I missed something. For what do you use regular expressions? P.S. sorry for my bad english ...

Regular expression for parsing links from a webpage?

I'm looking for a .NET regular expression extract all the URLs from a webpage but haven't found one to be comprehensive enough to cover all the different ways you can specify a link. And a side question: Is there 'one regex to rule them all'? Or am I better off using a series of less complicated regular expressions and just using mutlip...

Remove Quotes and Commas from a String in MySQL

I'm importing some data from a CSV file, and numbers that are larger 1000 get turned into "1,100" etc. What's a good way to remove both the quotes and the comma from this so I can put it into an int field? Edit: The data is actually already in a MySQL table, so I need to be able to this using SQL. Sorry for the mixup. ...

How do you retrieve selected text using Regex in C#?

How do you retrieve selected text using Regex in C#? I am looking for c# code that is equivalent to this perl code: $indexVal = 0; if($string =~ /Index: (\d*)/){$indexVal = $1;} ...

How do I bind a regular expression to a key combination in emacs?

For context, I am something of an emacs newbie. I haven't used it for very long, but have been using it more and more (I like it a lot). Also I'm comfortable with lisp, but not super familiar with elisp. What I need to do is bind a regular expression to a keyboard combination because I use this particular regex so often. What I've be...

Regex Rejecting matches because of Instr

What's the easiest way to do a "instring" type function with a regex. For example, how could I reject a whole string because of the presence of a single character such as ":" for example: "this" - okay "there:is" - not okay because of ":" More practically, how can I match the following string: //foo/bar/baz[1]/ns:foo2/@attr/text() ...

Parsing attributes with regex in Perl

Here's a problem I ran into recently. I have attributes strings of the form "x=1 and y=abc and z=c4g and ..." Some attributes have numeric values, some have alpha values, some have mixed, some have dates, etc. Every string is supposed to have "x=someval and y=anotherval" at the beginning, but some don't. I have three things I need ...

Pre-built regular expression patterns or Regex Libraries?

Does anyone use have a good regex library that they like to use? Most of the regexes that you find online either contain bugs or are so focused on the edge cases that it turns into a competition to validate whatever spec 100%. Of course you can write your own, but when you are billing by the hour its handy to have a library around. ...

Question about specific regular expression

I was reading this question about how to parse URLs out of web pages and had a question about the accepted answer which offered this solution: ((mailto\:|(news|(ht|f)tp(s?))\://){1}\S+) The solution was offered by csmba and he credited it to regexlib.com. Whew. Credits done. I think this is a fairly naive regular expression but it'...

Python Regular Expressions

I'm trying to implement string unescaping with Python regex and backreferences, and it doesn't seem to want to work very well. I'm sure it's something I'm doing wrong but I can't figure out what... >>> import re >>> mystring = r"This is \n a test \r" >>> p = re.compile( "\\\\(\\S)" ) >>> p.sub( "\\1", mystring ) 'This is n a test r' >>>...

Regex and unicode

I have a script that parses the filenames of TV episodes (show.name.s01e02.avi for example), grabs the episode name (from the www.thetvdb.com API) and automatically renames them into something nicer (Show Name - [01x02].avi) The script works fine, that is until you try and use it on files that have Unicode show-names (something I never ...

Need help writing a regex statement. [PHP]

So I'm working on a project that will allow users to enter poker hand histories from sites like PokerStars and then display the hand to them. It seems that regex would be a great tool for this, however I rank my regex knowledge at "slim to none". So I'm using PHP and looping through this block of text line by line and on lines like thi...

How do you use back-references to PCREs in PHP?

I read this PHP RegEx page, but either I'm missing something, misreading something, or it doesn't work the way they say. I'm guessing it's one of the first two. $str = preg_replace("([|]\d*)", "\1;", $str); ...

What did I do wrong here? [Javascript Regex]

So I am writing a registration form and I need the display name to be only numbers, letters and underscores. Have a look at my code and tell me what I'm doing wrong. <form method="post" action="/" onsubmit="return check_form()"> <input type="text" id="display-name" name="display-name" maxlength="255" /> <input type="submit" /> ...

RFC calculation in Java need help with algorithm

The RFC for a Java class is set of all methods that can be invoked in response to a message to an object of the class or by some method in the class. RFC = M + R where M = Number of methods in the class. R = Total number of other methods directly invoked from the M. Thinking C is the .class and J is the .java file of which we need to ...