regex

Regular Expressions: Is there an AND operator?

Obviously, you can use | (pipe?), to represent OR, but can you match 'and' as well? Specifically, I'm wanting to match paragraphs of text that contain ALL of a certain phrase, but in no particular order. ...

Regular expression for parsing CSV in PHP

I already managed to split the CSV file using this regex: "/,(?=(?:[^\"]\"[^\"]\")(?![^\"]\"))/" But I ended up with an array of strings that contain the opening and ending double quotes. Now I need a regex that would strip those strings of the delimiter double quotes. As far as I know the CSV format can encapsulate strings in double q...

Which is preferred: Regex.Replace() or. aRegexObject.Replace()?

This is a followup to this question The first two answers are both correct and complete and at the end of the day, produce exactly the same result. However, one uses a Regex object and calls the aRegex.Replace(...) method (Joel's answer) and the other uses the static Regex.Replace(...) method. (CMS' answer). Which method is preferred?...

C#, How can You make An Object Reinitialize itself?

Ok, in Perl causing an object to reinitialize itself is easy since it is represented by an assignable reference or pointer. C#, however, doesn't appear to like this. I wanted to create a subclass of System.Text.RegularExpressions.Regex whose pattern could be changed without using new objects and consuming memory for each. (private i...

PHP regex to get contents of a specific span element

I need some help ... I'm a bit (read total) n00b when it comes to regular expressions, and need some help writing one to find a specific piece of text contained within a specific HTML tag from PHP. The source string looks like this: <span lang="en">English Content</span><span lang="fr">French content</span> ... etc ... I'd like to ex...

Javascript String.replace(/\$/,str) works weirdly in jsp file

For simplicity, i have the following file named test.jsp: <script language="javascript"> alert("a$b".replace(/\$/g,"k")); </script> I put this file in my local server, then display it using firefox: http://localhost:8080/myproj/test.jsp. It works okay, the result alert string is: akb But when i put this file in a remote serve...

Format string as UK phone number

I'm looking for a routine that will format a string of numbers as a UK phone number. The routine should account for UK area codes that require different formatting (i.e. London compared to Edinburgh compared to Worcester) as well as mobile numbers. My phone numbers are stored in the database as strings, containing only numeric character...

Using Regex to edit a string in C#

I'm just beginning to use Regex so bear with my terminology. I have a regex pattern that is working properly on a string. The string could be in the format "text [pattern] text". Therefore, I also have a regex pattern that negates the first pattern. If I print out the results from each of the matches everything is shown correctly. The ...

RegEx to parse or validate Base64 data

Is it possible to use a RegEx to validate, or sanitize Base64 data? That's the simple question, but the factors that drive this question are what make it difficult. I have a Base64 parser that can not fully RELY on the input data to follow the RFC specs. So, the issue I face is maybe b64 data that is not broke into 78 (I think it's 78...

PHP regex: what is "class at offset 0"?

I'm trying to strip all punctuation out of a string using a simple regular expression and the php preg_replace function, although I get the following error: Compilation failed: POSIX named classes are supported only within a class at offset 0 I guess this means I can't use POSIX named classes outside of a class at offset 0. My ...

Regex to pull out C function prototype declarations?

I'm somewhere on the learning curve when it comes to regular expressions, and I need to use them to automatically modify function prototypes in a bunch of C headers. Does anyone know of a decent regular expression to find any and all function prototypes in a C header, while excluding everything else? Edit: Three things that weren't cle...

Python Regular Expression to add links to urls

I'm trying to make a regular expression that will correctly capture URLs, including ones that are wrapped in parenthesis as in (http://example.com) and spoken about on coding horror at http://www.codinghorror.com/blog/archives/001181.html I'm currently using the following to create HTML A tags in python for links that start with http an...

a simple regexp validator

How do a I create a validator, which has these simple rules. An expression is valid if it must start with a letter it must end with a letter it can contain a dash (minus sign), but not at start or end of the expression ...

Is there a good, online, interactive regex tutorial?

Now, I know both SQL and regexes just fine, but a few times on this site, I came across someone working through the exercises on SQLzoo.net. As far as I could tell, this was a wonderful online resource where someone can pretty easily learn SQL by example, writing many toy queries against several toy databases. I will likely redirect pe...

Expression Evaluation in C++

Hi, I'm writing some excel-like C++ console app for homework. My app should be able to accept formulas for it's cells, for example it should evaluate something like this: Sum(tablename\fieldname[recordnumber], fieldname[recordnumber], ...) tablename\fieldname[recordnumber] points to a cell in another table, fieldname[recordnumber] poi...

Empty out all methods in a file in vim, regex?

I am using the vim editor and I wanted to empty out all methods in the class, for instance class A { public: int getNumber() const { return number; } void setNumber(int num) { number = num; } }; I wanted to have a regex where I could substitute so that the result woul...

Python regular expressions with more than 100 groups?

Is there any way to beat the 100-group limit for regular expressions in Python? Also, could someone explain why there is a limit. Thanks. ...

Is this code snippet from Java to c# correct?

Hi folks, i'm trying to port some Java stuff to C#. I'm just wondering if the following C# code is the equivalent to the original Java source. Source: Java Code private static final Pattern SIMPLE_IDENTIFIER_NAME_PATTERN = Pattern.compile("^[a-zA-Z_][a-zA-Z0-9_]*$"); private static boolean isValidIdentifier(String s) { ...

Wikilinks - turn the text [[a]] into an internal link

I need to implement something similar to wikilinks on my site. The user is entering plain text and will enter [[asdf]] wherever there is an internal link. Only the first five examples are really applicable in the implementation I need. Would you use regex, what expression would do this? Is there a library out there somewhere that alread...

Regex to match all '&' before first '?'

Basically, I want to do "zipzam&&&?&&&?&&&" -> "zipzam%26%26%26?&&&?&&&". I can do that without regex many different ways, but it'd cleanup things a tad bit if I could do it with regex. Thanks Edit: "zip=zam&&&=?&&&?&&&" -> "zip=zam%26%26%26=?&&&?&&&" should make things a little clearer. Edit: "zip=zam=&=&=&=?&&&?&&&" -> "zip=zam=%26=...